...

View Full Version : Javascript function



heals1ic
06-23-2008, 01:21 AM
For the life of me I cannot seem to sort out what I am doing wrong here.

My firefox error console reports that signup is not a function :

The script is in the header.



<script language="JavaScript">
function signup(){
alert("Hello");
};
</script>
<form name="signup">
<table class="signuptbl" cellSpacing=0 cellPadding=0 border=0>
<tr>
<td align="right">
<label for="email">E-mail&nbsp;:&nbsp;</label>
</td>
<td align="left">
<input class="prof" type="text" name="email" size="35" maxlength="80" value=""> *
</td>
<td align="center" colspan="2">
<input type="button" name="subsignup" value="SUBMIT" onclick="signup();">
</td>
</tr>
</table>
</form>


I know it is probably something simple but I have spent quite a bit of time stripping the code back to its barest to diagnose but still I cannot get this to work.

rodrix
06-23-2008, 04:13 AM
[CODE]
<script language="JavaScript">
function signup(){
alert("Hello");
};
</script>


If I am not mistaken your error is having an extra semi-colon ";".
Should be:

function signup(){
alert("Hello");
}

NOT

function signup(){
alert("Hello");
};

Hope this helps! :)

Trinithis
06-23-2008, 04:38 AM
I tested it, and for some reason, the <form name="signup">'s name is conflicting with the js function. Renaming either one of them solves the problem.

liorean
06-23-2008, 08:48 AM
Kor recently had a similar question. As I answered in 698464, inline event handlers have a scope hierarchy which contain the form control's element node, the form's element node, probably the document node though I haven't confirmed that part, and only as third or fourth in the scope chain the JavaScript global object i.e. window. That means that names, IDs and JavaScript properties on the form object, the form control object and IDs and names on other form controls in the same form can shadow names in the global JavaScript environment.

Also note that in Internet Explorer, names and IDs are global variables and thus you should NEVER use a global variable or function name which is the same as an element name or ID.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum