Select option [0] value

I have an application that allows the user to look up order detail. When they click on that order number they can open a trouble ticket.
I pass most of the order information to the trouble ticket which is built on the fly based on how they answer questions. In some cases I need to collect the data again but allow them to change it. It was easy enough for input boxes but selects gave me some trouble.

Here is what i ended up with. TR_SEGMENT is what I passed from the order into a hidden formfield. I then reset the initial Select option for segment – Normally “Select One” with this value. I have to check and see if the form element segment is there first then update the value and the display text.

javascript
if(document.qform.segment != null && document.qform.segment != 'undefined'
&& document.qform.TR_SEGMENT.value != 'undefined'){
document.qform.segment[0].value = document.qform.TR_SEGMENT.value;
document.qform.segment[0].text = document.qform.TR_SEGMENT.value;

Cup size   
Select size then click on coffee cup.
This entry was posted in Code, Javascript, Snippets. Bookmark the permalink.