ianc
03-21-2007, 03:58 AM
Hi all,
I have a javascript function which I need to use to enable and disable and set attributes of certain elements on my form.
I have a drop down field called 'dropDownList'
I have a submit button called 'addItem'
The HTML will look like this
<select id="dropDownList" name="dropDownList">
<option>Select Type</option>
<option value="1">1 - dog</option>
<option value="2">2 - pig</option>
<option value="3">3 - cow</option>
</select>
<button type="button" id="addItem" name="action" value="addItem"
onmouseover="validate_form();">
Add
</button>
I want my javascript to do the following:
function validate_form() {
var dropDownListElem = document.getElementById('dropDownList');
var addItemElem = document.getElementById('addItem');
If (dropDownListElem.value == "Select Type") {
addItemElem.disabled = true;
<Only now I want to set the onmouseover actions for the 'dropDownList' element... How do I do this?>
}
}
note: I also have a smaller function
function activate_Button(fieldid) {
var element = document.getElementById(fieldid);
element.disabled = false;
}
to reactivate the disabled button.
I'm not to familiar with the DOM for handling user events... I'm guessing it'll be something like dropDownList.onmouseover=<action> but that didn't work.
Help?
Thanks
I have a javascript function which I need to use to enable and disable and set attributes of certain elements on my form.
I have a drop down field called 'dropDownList'
I have a submit button called 'addItem'
The HTML will look like this
<select id="dropDownList" name="dropDownList">
<option>Select Type</option>
<option value="1">1 - dog</option>
<option value="2">2 - pig</option>
<option value="3">3 - cow</option>
</select>
<button type="button" id="addItem" name="action" value="addItem"
onmouseover="validate_form();">
Add
</button>
I want my javascript to do the following:
function validate_form() {
var dropDownListElem = document.getElementById('dropDownList');
var addItemElem = document.getElementById('addItem');
If (dropDownListElem.value == "Select Type") {
addItemElem.disabled = true;
<Only now I want to set the onmouseover actions for the 'dropDownList' element... How do I do this?>
}
}
note: I also have a smaller function
function activate_Button(fieldid) {
var element = document.getElementById(fieldid);
element.disabled = false;
}
to reactivate the disabled button.
I'm not to familiar with the DOM for handling user events... I'm guessing it'll be something like dropDownList.onmouseover=<action> but that didn't work.
Help?
Thanks