Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2004
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript function

    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.

    Code:
    <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.

  • #2
    New to the CF scene
    Join Date
    Jun 2008
    Location
    Buenos Aires
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by heals1ic View Post
    [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!

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Location
    USA
    Posts
    527
    Thanks
    26
    Thanked 74 Times in 72 Posts
    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.
    Trinithis

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Kor recently had a similar question. As I answered in http://codingforums.com/showthread.php?p=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.
    Last edited by liorean; 06-23-2008 at 09:56 AM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •