I need some help in trying to access the values of form fields on a NewForm.aspx page. The goal is to have one field (Title) automatically updated based on the values that are entered in another text field (JobID) and the value that is selected from a Choice field drop down list (Designer). The title will need to be changed when either of those fields is changed. Specifically, where I need help is in dealing with the drop down lists.
Question 1) How do I add an OnChange event for the drop-down list?
Question 2) How do I programmatically access the text (and/or value) of the selected item in the drop-down list?
What I’ve done is added a CEWP web part to the NewForm.aspx page that has JavaScript to handle all of this.
I’ve added an OnChange event for my text field without a problem, which calls when a change is made to the JobID field. I’ve done that as follows:
<script language=javascript for="urn:schemas-microsoft-com:office:office#JobID" event="onchange">
setTitle();
</script>
And I can get the value of the JobID without a problem. I’ve done that as follows:
function getJobID() {
var elems = document.getElementsByTagName("INPUT");
for (var i=0;i<elems.length;i++) {
if(elems[i].title=='Job ID') {
return elems[i].value;
}
}
return "";
}
Does anyone have any suggestions on how I can get the value of and respond to changes to a drop-down list? I spent hours on this yesterday and would appreciate any help anyone can offer.