Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
How can I pass an array to javascript function?
Old 07-14-2007, 11:57 PM How can I pass an array to javascript function?
Extreme Talker

Posts: 189
Trades: 1
Here is the situation:
Code:
<!-- declare the array -->
<script type="text/javascript">
var prefix = new Array();
prefix['type'] = 'label';
prefix['text'] = 'more';
</script>

<!-- Call the function addField and attempt to pass the array -->
<input type="button" value="Add more field" onclick="addField(prefix);" />

I'm trying to pass an array into a function, which is called when the user clicks on the button but this does not seem to work. Any suggestion is really appreciated.

Thanks all.
__________________

Please login or register to view this content. Registration is FREE
yellow1912 is offline
Reply With Quote
View Public Profile Visit yellow1912's homepage!
 
 
Register now for full access!
Old 07-16-2007, 09:12 AM Re: How can I pass an array to javascript function?
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
Try changing your button code to read
HTML Code:
<input type="button" value="Add more field" onclick="addField(window.prefix);" />
__________________

Please login or register to view this content. Registration is FREE

willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 07-21-2007, 12:53 PM Re: How can I pass an array to javascript function?
Extreme Talker

Posts: 189
Trades: 1
It was a "scope" problem. I declared the variable when the user clicks on the button and it works. I will try your suggestion as well.

Thank you.
__________________

Please login or register to view this content. Registration is FREE
yellow1912 is offline
Reply With Quote
View Public Profile Visit yellow1912's homepage!
 
Reply     « Reply to How can I pass an array to javascript function?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11865 seconds with 12 queries