loonatik
06-24-2003, 06:29 PM
Given:
<script>
str = "username,password,newsletter";
var a = str.split(",");
function show(){
if(!document.reg.a[0].value){
alert(document.reg.a[0].value);
return false;
}
return true
}
</script>
<form name="reg">
username <input type="text" name="username">
<input type="submit" name="submit" value="submit" onclick="return validate()">
</form>
An alert should popup with the word "username" on it. However, this just submits and no alert. It's actually "document.reg.a[0].value" that doesn't evaluate to anything and a[0] is 'username'. I want for it to alert and the form not to submit if username is blank. solutions? Thanks.
<script>
str = "username,password,newsletter";
var a = str.split(",");
function show(){
if(!document.reg.a[0].value){
alert(document.reg.a[0].value);
return false;
}
return true
}
</script>
<form name="reg">
username <input type="text" name="username">
<input type="submit" name="submit" value="submit" onclick="return validate()">
</form>
An alert should popup with the word "username" on it. However, this just submits and no alert. It's actually "document.reg.a[0].value" that doesn't evaluate to anything and a[0] is 'username'. I want for it to alert and the form not to submit if username is blank. solutions? Thanks.