iEntry 10th Anniversary Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack Thread Tools
Old January 15th, 2007, 03:07 PM   #1
New Member
 

Join Date: Jan 2007
Location: North Yorkshire
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Eagle is on a distinguished road
problem calling function via onClick

This is my first post so I hope someone can help me out. I am very new to javascript and am having a problem calling a function using the onClick event linked to a button. I have produced the code below which generates a form with a series of boxes to complete. The user inputs a number at the first window.prompt which generates a form with the corresponding number of rows of fields. When the form has been completed I want to be able to call a function called assess_risk which currently only has a window.alert in it for testing purposes but will ultimately collect the data from each form field in a series of arrays which have been defined, and then used to perform some calculations. However when I click the button which calls the assess_risk function I get an error in IE. In Firefox 1.5 it also doesn't work and using the javascript console it says the error is assess_risk not defined.

I would really appreciate any help in understanding where I'm going wrong!

thanks
Attached Files
File Type: txt riskassess.txt (2.7 KB, 44 views)
Eagle is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old January 15th, 2007, 03:36 PM   #2
New Member
 

Join Date: Jan 2007
Location: Michigan
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 joe3dge is on a distinguished road
Re: problem calling function via onClick

that problem is an easy fix

you put:
Code:
document.write("<input type='button' value='Complete Assessment' onClick= assess_risk()>");
you need quotes around your 'assess_risk()' function call

you should have:
Code:
document.write("<input type='button' value='Complete Assessment' onClick='assess_risk()'>");
joe3dge is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old January 15th, 2007, 03:47 PM   #3
New Member
 

Join Date: Jan 2007
Location: North Yorkshire
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Eagle is on a distinguished road
Re: problem calling function via onClick

thanks for your quick reply but I had already tried it with and without the quotes around the function call and it makes no difference, still get same errors?
Eagle is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old January 15th, 2007, 04:28 PM   #4
New Member
 

Join Date: Jan 2007
Location: Michigan
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 joe3dge is on a distinguished road
Re: problem calling function via onClick

ok i think i found the real problem this time
(although im pretty sure ur going to need those qutoes anyways)

the problem is that you are putting your "document.write()" commands inside a function in the <head> tags. because of this, the javascript compiler does not know where to put the text. on thing u could do, is create a <div> element and put the text inside that, with the .innerHTML property.

ok i dont know if i explaed that well, so im going to add my own version of the code SOON
joe3dge is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old January 15th, 2007, 04:37 PM   #5
New Member
 

Join Date: Jan 2007
Location: Michigan
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 joe3dge is on a distinguished road
Re: problem calling function via onClick

ok i got it working this time
i have the code attached

another adavantage of using the inner HTML property instead of the documwnt.write90 method is that the link stays on the page, so u can rerun the program multiple times.

i hope u enjoy ur now-working program
Attached Files
File Type: txt riskassess-1.txt (3.3 KB, 50 views)
joe3dge is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old January 15th, 2007, 06:41 PM   #6
New Member
 

Join Date: Jan 2007
Location: North Yorkshire
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Eagle is on a distinguished road
Smile Re: problem calling function via onClick

Thank you very much for your help, it's much appreciated. Now I can begin to write the assess_risk function in full.

I've alot to learn!!
Eagle is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 28th, 2009, 04:38 PM   #7
New Member
 

Join Date: Aug 2009
Location: Nowhere
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 greater is on a distinguished road
Re: problem calling function via onClick

I am having the same problem, but your text file with the solution is empty. Can you please re-post your fix?

Thanks!
greater is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
call , function , onclick


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
calling functions in a function fatsurfer PHP 1 June 12th, 2008 06:53 PM
Problem: onClick Function mihirc HTML, XHTML and CSS 16 July 28th, 2007 08:20 AM
Need help on an onclick function DaveKenroy JavaScript 3 January 28th, 2007 08:31 AM
plz help me verify this... calling function melvinoyh JavaScript 0 May 28th, 2006 10:35 PM
onclick function tomd1985 JavaScript 0 March 13th, 2006 03:20 PM


Search Engine Optimization by vBSEO 3.2.0 RC8