Hi,

I'm getting this.form undefined error message when I submit it. Do I miss anything?

Thanks

function signup_scramble(uid)
{
    alert(uid.value);

    return false;
}


<form action="do_signup" method="post" onsubmit="return signup_scramble(this.form.text_username)">

Username : <input type="text" name="text_username" value="" /><br />
Password : <input type="password" name="text_password" value="" /><br />
<input type="submit" name="submit_button" value="Signup" />

</form>
Member Avatar for stbuchok

Change it to the following (the code is not tested)

function signup_scramble(element)
{
        alert(element.value);
        return false;
}
<form action="do_signup" method="post" onsubmit="return signup_scramble(document.getElementById('text_username'))">
Username : <input type="text" id="text_username" value="" /><br />
Password : <input type="password" id="text_password" value="" /><br />
<input type="submit" id="submit_button" value="Signup" />
</form>

You can use getElementByName, howerver this will return an array as the name attribute does not need to be unique. I would suggest using the id attribute unless you really need to use name.

You could also try this

<script type="text/javscript">
function signup(){
    var username = document.getElementById("text_username").value;
    var password = document.getElementById("text_password").value;
    alert(username + " " + password);
    return false;
}
</script>


<form action="do_signup" method="post" onsubmit="signup()">
Username : <input type="text" id="text_username" /><br />
Password : <input type="password" id="text_password" /><br />
<input type="submit" name="submit_button" value="Signup" />

</form>

Or if your form and inputs had a name:

<script type="text/javascript">
function greeting(){
    alert("Welcome " + document.forms["frm1"]["fname"].value + "!")
}
</script>
</head>
<body>

What is your name?<br />
<form name="frm1" action="submit.htm" onsubmit="greeting()">
<input type="text" name="fname" />
<input type="submit" value="Submit" />
</form>

Hope this helps

Thanks guys. You gave me hint.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.