View Single Post
Old 04-24-2010, 04:51 AM  
nation-x
Confirmed User
 
nation-x's Avatar
 
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
Quote:
Originally Posted by Jakez View Post
How the hell would I pass an associative array to a javascript function?

Shitty example:

<a onclick="test(arr['item']='Item Name', arr['price']='4.95');">click</a>

function test(arr)
{
alert(arr['item'] + arr['price']);
}
why not do it like this instead

http://nation-x.com/test.html

Code:
<script type="text/javascript">
var arr = new Object();

function testIt() {
	for (var i in arr) {
		alert('arr[\''+i+'\'] is ' + arr[i])
	}
}
</script>

If you click <a href="#" onClick="arr.item='Item Name'; arr.price='4.95';testIt(); return false;">this link</a> this script is executed:</p>
nation-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote