JavaScript / Submit Form Query

Ginger_Ale

Lurker
Retired Moderator
Joined
Jul 23, 2004
Messages
8,802
Location
Red Sox Nation
Probably a simple question for most people, I couldn't find it documented anywhere. Simply, what I want is a text box where people write an answer to a question, a submit button that has an onClick javascript function, and then it will answer "Right" or "Wrong". Here's so far:

Code:
<form name="form1"><input type="text" name="input1"><input type="Submit" onClick="submit()">
<script language="JavaScript">
function submit()
{
if (document.testform.a == guess)
{
document.form1.input1.value=Correct;
}
else
{
document.form1.input1.value=Wrong;
}
}
</script>

I am most certainly doing something wrong as I haven't used JS in a while... some help is appreciated, thanks.
 
I'd use something like that:
HTML:
<form name="form1"><input type="text" name="input1"><input type="Submit" onClick="Javascript:sendme()">
        <script language="JavaScript">
    function sendme()
    {
    if (document.form1.input1.value == "guess")
      {
      alert("Correct");
      }
    else
      {
      alert("Wrong");
      }
    }
  </script>


I wouldn't use submit() as the name for your function, since it's a reseverd term.
 
Back
Top Bottom