I have two select blocks in my html form:
<select id="select1">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<select id="select2" onchange="someFunc()">
<option>A/option>
<option>B</option>
</select>
I have a validateForm() function called from the form tag @onSubmit. the "someFunc" function populates some innerHTML elsewhere in the form. The issue I'm having, is that when I hit submit, the value of select1 reverts to its original default value, and the validateForm function fails.
the someFunc function is really long, so I didn't post the whole thing, but essentially what it does is check a string value and populate html, like:
if(select2.value = 'A'){
document.getElementById('anotherElement').innerHTML= '<h1>a new tag</h1>';
}
is there another att besides @onChange?
Ok, here is a complete html form that describes the problem I am having:
<html>
<head>
<title>javascript q</title>
<script>
function updateTag(){
document.getElementById('newHeading').innerHTML='<p id="status">updated</p>';
}
function validateForm(){
var s1 = document.getElementById('select1');
var s2 = document.getElementById('select2');
if( s1.value = 'please select' ){
alert('please select a value from the pulldown');
return false;
}
// updated html needs to have been performed and value selected
if(document.getElementById('status') == null ){
alert('status does not exist');
}
}
</script>
</head>
<body>
<h1>Javascript Q</h1>
<form id="testForm" onSubmit="return validateForm();">
<select id="select1">
<option>please select</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<select id="select2" onchange="updateTag()">
<option>please select</option>
<option>a</option>
<option>b</option>
<option>c</option>
</select>
<input type="submit" value="submit"/>
<div id="newHeading">
</div>
</form>
</body>
</html>
what happens is, I select a value from each pulldown, hit submit, then the value of select1 reverts to its orig val, and fails the validation
hope that's better.
thanks, bp