And now, nothing works in the page =/
[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function select_validate(formulario,campo,rotulo){
if(document[formulario][campo].selectedIndex == "0" ){
document[formulario][campo].focus();
alert('Especifique '+rotulo+'!');
return false;
}
return true;
}
</script>
<script type="text/javascript">
function validate () {
// Option must be selected
if (!select_validate('form','comboselect','Option')) {
return false;
}
valor = document.form.comboselect.value;
if (valor === "1" || valor === "2" || valor === "3") {
if (input1 == "") {
alert("Input 1 must be filled.");
document.form.input1.focus();
return false;
} else if (input2 == "") {
alert("Input 2 must be filled.");
document.form.input2.focus();
return false;
} else {
if (input3 == "") {
alert("Input 3 must be filled.");
document.form.input3.focus();
return false;
}
}
return true;
}
</script>
</head>
<body>
<form action="test_validate.html" method="post" name="form" onsubmit="return validate()">
<select name="comboselect">
<option value="0" selected>-------------</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select><br />
<label>Input 1</label><input name="input1" size="40" type="text" /><br />
<label>Input 2</label><input name="input2" size="40" type="text" /><br />
<label>Input 3</label><input name="input3" size="40" type="text" /><br />
<input type="submit" value="Send" title="Send" />
</form>
</body>
</html>
[/HTML]
Quote:
Originally Posted by acoder
Have you not set input1, input2, etc. to document.form.input1.value, etc.?
Post the rest of the code especially how the function is called.