admin管理员组

文章数量:1316388

I have JavaScript code including several functions, the main one being CheckForm().

The function is called by clicking the 'Submit' button:

<td><input type="submit" name="submit1" id="submit1" value="Register" onclick="return CheckForm();"/></td>    

But when the button is pressed nothing happens (the function isn't performed). What can I do to fix this?

I have JavaScript code including several functions, the main one being CheckForm().

The function is called by clicking the 'Submit' button:

<td><input type="submit" name="submit1" id="submit1" value="Register" onclick="return CheckForm();"/></td>    

But when the button is pressed nothing happens (the function isn't performed). What can I do to fix this?

Share Improve this question edited Apr 12, 2022 at 15:57 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Apr 2, 2013 at 10:42 user2235692user2235692 2712 gold badges3 silver badges5 bronze badges 4
  • 7 Post the code for the function – Jeff Shaver Commented Apr 2, 2013 at 10:44
  • 2 put a console.log / or alert in the top of the function so you know if it gets fired at all – Matthias Wegtun Commented Apr 2, 2013 at 10:47
  • 1 Anything in the error console in firebug? – topcat3 Commented Apr 2, 2013 at 10:47
  • Can you write the skeleton of checkForm code? Can you check the browser log to see if there is any error in the page? – Peter Tadros Commented Apr 2, 2013 at 10:48
Add a ment  | 

2 Answers 2

Reset to default 2

Have you tried debugging your code using FireBug or jsFiddle?

Some possible causes are an incorrectly named function or function call(remember that JavaScript is case sensitive), an error in your function or your JavaScript code not being referenced in your page.

If you aren't using either of the above tools then try using a console.log or alert inside your function to see if it is being called.

You can use it like this.

function CheckForm()
{
 //doing stuff
  return true;
}

<form id="formToCheck"></form>


$('#formToCheck').submit(CheckForm);

Hope it helps

if you want to do it without jquery just add on

   <form onSubmit="return CheckForm()"></form>

You can read more about form validation without jQuery here -> http://www.w3schools./js/js_form_validation.asp#gsc.tab=0

Maybe if it doesn't work you have some errors. Check JS console in your browser and remove them.

本文标签: htmlJavaScript onclick() function not workingStack Overflow