Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set value in drop down menu

I have that code:

 </script>
<!-- End HTML Area -->
</div>
</td>
</tr>
<tr>
<td height='47' colspan='4'></td>
<td colspan='13'  valign='top' align='right'>
<table cellpadding='0' cellspacing='0' cols='1'  class='PSGROUPBOXWBO'  width='934'>
<tr><td class='PSGROUPBOXLABEL'  align='right'><a name='DERIVED_RC_IRSL_MT_TRIPLE_GB' id='DERIVED_RC_IRSL_MT_TRIPLE_GB' tabindex='-1' href="javascript:submitAction_win6(document.win6,'DERIVED_RC_IRSL_MT_TRIPLE_GB');"><img src='/cs/crmprod/cache/PT_COLLAPSE_HEB_1.gif' alt='הסתרת הנתונים' title='הסתרת הנתונים' border='0' /></a>&nbsp;סיווג פניה לאחר טיפול בלקוח&nbsp;</td></tr>
<tr><td width='932'>
<table  id='ACE_width' border='0' cellpadding='0' cellspacing='0' cols='10' width='932' class='PSGROUPBOX' style='border-style:none' >
<tr>
<td width='0' height='4'></td>
<td width='70'></td>
<td width='3'></td>
<td width='246'></td>
<td width='41'></td>
<td width='3'></td>
<td width='247'></td>
<td width='49'></td>
<td width='3'></td>
<td width='270'></td>
</tr>
<tr>
<td height='4' colspan='3'></td>
<td rowspan='2'  valign='top' align='right'>
<select name='MT_CASE_EXTRA_MT_CAT_SEQ_NUM' id='MT_CASE_EXTRA_MT_CAT_SEQ_NUM' tabindex='360' size='1'  class='PSDROPDOWNLIST' style="width:207px; " onchange="if (document.readyState == 'complete') submitAction_win6(this.form,this.name);" >
<option value="0" selected='selected'></option>
<option value="21">test</option>
<option value="23">test2</option>
<option value="64">test3</option>
<option value="41">test4</option>
<option value="61">test5</option>
<option value="141">test6</option>
<option value="22">test7</option>
<option value="63">test8</option>
<option value="24">test9</option>
</select>

I try to make JavaScript code. When the user copy+paste it to the address field in the browser the value I wanted will be automatically selected in the menu.

Here is what I do:

javascript:function GetSelectedItem() {     
    var e = document.getElementById("selected24");
    var strSel = "The Value is: " + e.options[e.selectedIndex].value + " and text is: " + e.options[e.selectedIndex].text;
    alert(strSel);
    } 
like image 889
Xtrician Avatar asked Oct 21 '12 13:10

Xtrician


People also ask

How do I assign a value to a drop-down list in Excel?

Select the cells that you want to contain the lists. On the ribbon, click DATA > Data Validation. In the dialog, set Allow to List. Click in Source, type the text or numbers (separated by commas, for a comma-delimited list) that you want in your drop-down list, and click OK.

How do you assign a value to a drop-down list in HTML?

The select tag in HTML is used to create a dropdown list of options that can be selected. The option tag contains the value that would be used when selected. The default value of the select element can be set by using the 'selected' attribute on the required option. This is a boolean attribute.

How do I set the default value in dynamic drop down?

Just add the selected attribute to one of the option s to make it the default selected option. Show activity on this post. You want to display a default value in your dropdown list of years.


1 Answers

related question: How do I programmatically set the value of a select box element using javascript?

If you want to set selected value of your <select> element, you should do it like so:

var newValue = 24; // or whatever
document.getElementById('MT_CASE_EXTRA_MT_CAT_SEQ_NUM').value = newValue;
like image 73
pckill Avatar answered Sep 26 '22 02:09

pckill