|
Posted by Hilarion on 08/23/05 23:06
mscurto@gmail.com wrote:
> I am new to Javascripting and I am teaching myself. I have some simple
> code here I need help with.
>
> It works fine however if a user enters in data in one text box but not
> the other, an error message appears (which is correct). Is there a way
> to keep the entered textbox value if the error message pops up? In
> other words, If I enter in text in the 'Hourly' textbox but not the
> yearly, once I hit continue, is there a way to prevent the data from
> disappearing in the 'Hourly' textbox?
>
> Thanks in advance for your help.
>
> <html>
> <head>
> <script type="text/javascript">
> function checkMoney(){
> var text1=jsform.txt1.value
> var text2=jsform.txt2.value
> if (jsform.txt1.value == "") {
> alert("Missing Data in Field 1")
return false;
> }
> else if (jsform.txt2.value == "") {
> alert("Missing Data in Field 2")
return false;
> }
> else { alert("Successfully submitted!")
> }
> }
> </script>
> </head>
> <body>
> <form name="jsform" method="post" onsubmit="return checkMoney()">
> Hourly<input type="textbox" name="txt1"><br>
> Yearly<input type="textbox" name="txt2"><br>
> <input type="submit" name="submit" value="continue"><br>
> </form>
> </body>
> </html>
Your values did NOT disappear. You did not signalise that
submission of the form should be canceled (by returning false
from checkMoney), so the data was submited. You did not
specify "action" for "<form>", so the browser guessed that
it should submit data to the same address it was submited
from (different browsers may do different guessing, so you
should not ommit "action") this way showing you again the
same empty form.
Hilarion
[Back to original message]
|