Hi all, this is my first post here…so please be gentle 🙂
I’m having a really irritating problem with a form that I’ve created. Basically I’m doing some client side validation on the form before it gets submitted. Obviously to do this I need to get the value of the form elements. Part of the code is also hidden/displayed using CSS and so it’s in a DIV element. The problem arrises when I try to read the value of the elements within the DIV…The code is below and is XHTML 1.0 valid. The most annoying thing though is that if I take the <select> element out of the DIV then it works….
The form…
<form enctype=”multipart/form-data” method=”post” action=”” name=”main_form” onsubmit=”return validator();”>
<input name=”headline” type=”text” value=”Enter Headline” size=”80″ maxlength=”200″ />
<input type=”hidden” name=”posted” value=”true” />
<div id=”options”>
<select name=”related1″>
<option value=”headline”>Headline Article</option>
<option value=”other”>Other Article</option>
</select>
</div>
<input type=”submit” />
</form>
And the Javascript…
function validator() {
var value = document.getElementsByName(‘related1’)[0].value;
}
return false;
}
I’ve also tried…
var value = document.main_form.related1.value;