Page 1 of 1

Can't call javascript from an HTML form

Posted: Thu Jul 26, 2007 7:33 am
by davidtube
I have the following code which seems to not call the javascript function from within the form. However if the form closes before the html buttons, it works properly. Why can I not get the functions to call from inside the form?

Code: Select all

<script type="text/javascript">
<!--
function join()
{
		if (document.form1.password.value.length < 1) {
		alert("enter your details");
		return false;
	}
	document.Form1.action = "http://example.com/"
}
//-->
</script>
This doesn't work.

Code: Select all

<form name='form1' method='post' >
      <input name='password' type='password' id='password'>
      <input type='submit' name='join' id='join' value='Join' OnClick='return join();'/>
</form>

This does work.

Code: Select all

<form name='form1' method='post' >
      <input name='password' type='password' id='password'>
</form>
      <input type='submit' name='join' id='join' value='Join' OnClick='return join();'/>

Posted: Thu Jul 26, 2007 8:04 am
by miro_igov
join() is reserved in javascript, try renaming this function and use some HTML editor with code colors so you will never have such issues of using reserved words.

Posted: Thu Jul 26, 2007 8:20 am
by davidtube
:D Great thank you.