Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 3rd, 2007, 11:22 AM
Registered User
Join Date: Nov 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default onClick woes

Hi Everyone,

I have a problem with my javascript code. I am trying to pass a parameter to the checkAnswer function during using the onClick event handler.

I wrote the following lines of code:

var option2= document.createElement("input");
    option2.type = "button";
      option2.name = alldetails[3];
      option2.id = "test123";
      option2.value = alloptions[1];
      var testx = option2.name;
  // alert(testx);
    option2.onclick = new Function('checkAnswer(' + testx + ')'

Where alldetails[3] = “Europe” (I string value in an array).

function checkAnswer(response)

When I click my button, nothing happens. The firefox error console says

“Error: Europe is not defined”

Any help would be apprectiated. I basically want the value from the array to be passed to another function upon clicking the button.

Reply With Quote
  #2 (permalink)  
Old November 3rd, 2007, 01:13 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

There are a number of ways:
option2.onclick = function(){checkAnswer(this.name);};
I think that's neater or
option2.onclick = new Function("checkAnswer('" + testx + "');");
what you had but your quotes were wrong.


Joe (Microsoft MVP - XML)
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Installation woes gcallaway Beginning PHP 9 March 31st, 2008 07:05 PM
Array woes hillbilly geek PHP How-To 2 January 8th, 2006 12:28 AM
Form woes komputatek Access 2 March 15th, 2005 11:47 AM
Installation woes mattm BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 June 26th, 2003 03:40 PM

All times are GMT -4. The time now is 05:29 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.