Sharepoint Forum

 
Home » Forum » Sharepoint       Ask a questionRSS Feeds

Javascript to access choice form fields

  Asked By: Bridget Wagner         Date: Dec 17, 2006      Category: Sharepoint      Views: 1094
 

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.

Tagged:            

 

1 Answer Found

 
Answer #1       Answered By: Tejaswani Barve          Answered On: Dec 17, 2006       

You can always rewrite the ListFormWebPart … More on that idea is in my article at http://www.devx.com/webdev/Article/30026

 
Didn't find what you were looking for? Find more on Javascript to access choice form fields Or get search suggestion and latest updates.


Your Answer
  • Answer should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].