Can't call javascript from an HTML form

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
davidtube
Forum Commoner
Posts: 79
Joined: Sun Mar 25, 2007 8:42 pm

Can't call javascript from an HTML form

Post 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();'/>
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post 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.
davidtube
Forum Commoner
Posts: 79
Joined: Sun Mar 25, 2007 8:42 pm

Post by davidtube »

:D Great thank you.
Post Reply