0

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>

Edited by veledrom: .

3
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by veledrom
0

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.

Edited by stbuchok: Original post was for a diferent post.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.