|
Javascript Validation form not working in Chrome?
Hi,
What i am trying to do is use forms to repeat what I type in the text box as a string when i click.
I have a form with a text box and a submit button, currently when i type in the text box it will give an error if i have no text in the text box it does this correctly. The else statement of my code will show a welcome message followed by var x which gets the value from the text box. so the user types in their name and it returns the value.
The problem i have is that when i open it with Chrome and enter a value the message shows up for a split second and then goes away and the text box is left empty. As with the error message which displays that they haven't typed anything which remains. The code works in dreamweaver but when I open it doesn't work quite right. Here is my code:
function validateForm()
{
var x=document.forms["myForm"]["fname"].valu…
if (x==null || x=="")
{
document.getElementById('bla').inner… enter your name";
return false;
}
else
{
document.getElementById("bla").inner… " +x;
}
}
HTML:
<form name="myForm" onsubmit="return validateForm()">
First name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>
<p id="bla"></p>
also idk if its worth to note the address bar changes whenever i enter a value, but the return value isnt displayed.
/index.html?fname=John
What am i doing wrong and is there an easier way to do this?
|