![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Industry Role:
Join Date: Jan 2004
Location: oddfuturewolfgangkillthemall!!!!!!!
Posts: 5,656
|
Javascript experts?
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']); } |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Bollocks
Industry Role:
Join Date: Jun 2007
Location: Bollocks
Posts: 2,792
|
I don't know of a syntax that will let you do it that way, maybe just pass it in as a string of key and value pairs and have your function build the array from them.
__________________
Interserver unmanaged AMD Ryzen servers from $73.00 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 | |
Confirmed User
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
|
Quote:
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> |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 | |
Confirmed User
Industry Role:
Join Date: Jan 2004
Location: oddfuturewolfgangkillthemall!!!!!!!
Posts: 5,656
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Industry Role:
Join Date: Jan 2004
Location: oddfuturewolfgangkillthemall!!!!!!!
Posts: 5,656
|
Fuck, if I run this more than once on a page then old arguments are still passed through, unless I re-define them, then it's all good, but if I'm not using one of them on the 2nd time it will still be there from the first one. I tried clearing everything each time the function is run but it still persists. Maybe I need to clear the object each time or something? Haven't tried that yet I gotta run somewhere real quick..
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Join Date: Nov 2004
Location: Moonland
Posts: 552
|
Code:
<a onclick="test({name:'Item Name', price:4.95});">click</a> function test(item) { alert(item.name + ': $' + item.price.toFixed(2)); } |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 | |
Confirmed User
Industry Role:
Join Date: Jan 2004
Location: oddfuturewolfgangkillthemall!!!!!!!
Posts: 5,656
|
Quote:
![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |