By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,668 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

set multiple indexs useing DOM is it possible?

100+
P: 130
hello all.

i am trying to set few index's in my multiple select,

i can get the index out of there but it looks like i cant set it
please advice
snippet:
Expand|Select|Wrap|Line Numbers
  1. var sel = document.getElementById('select_multi');
  2.     for(i=0;i<sel.length;i++){
  3.         if(id[i] == id_xml[sel.options[i].value])
  4.             sel.selectedIndex = i;    
  5.  
i want to highlight few items in that select box; this code only higlight the last one :(
doesn't make seance
thanks
May 19 '09 #1
Share this Question
Share on Google+
6 Replies


RamananKalirajan
100+
P: 607
I dont get with your multiple index, are u looking for something like this...

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <script type="text/javascript">
  4.            function doThis()
  5.            {
  6.                 var zz= document.getElementById('mySelect1');
  7.                 var yy= document.getElementById('mySelect2');
  8.                 for(var i=0;i<zz.length;i++)
  9.                 {
  10.                     if(zz.options[i].selected)
  11.                     {
  12.                        //alert(zz.options[i].value);
  13.                         var temp = zz.options[i].value;
  14.                         for(var j=0;j<yy.length;j++)
  15.                         {
  16.                             if(yy.options[j].value==temp)
  17.                                yy.options[j].selected="true";
  18.                         }
  19.                     }
  20.                 }
  21.            }
  22.  
  23.         </script>
  24.     </head>
  25.     <body>
  26.         <table>
  27.             <tr>
  28.                 <td>
  29.                     <select id="mySelect1" multiple size="15">
  30.                         <option value="option1">option1</option>
  31.                         <option value="option2">option2</option>
  32.                         <option value="option3">option3</option>
  33.                         <option value="option4">option4</option>
  34.                         <option value="option5">option5</option>
  35.                         <option value="option6">option6</option>
  36.                         <option value="option7">option7</option>
  37.                         <option value="option8">option8</option>
  38.                         <option value="option9">option9</option>
  39.                         <option value="option10">option10</option>
  40.                         <option value="option11">option11</option>
  41.                         <option value="option12">option12</option>
  42.                         <option value="option13">option13</option>
  43.                         <option value="option14">option14</option>
  44.                         <option value="option15">option15</option>
  45.                     </select>
  46.                 </td>
  47.                 <td valign="middle">
  48.                     <input type="button" value="highlight" onclick="doThis()">
  49.                 </td>
  50.                 <td>
  51.                     <select id="mySelect2" multiple size="15">
  52.                         <option value="option1">option1</option>
  53.                         <option value="option2">option2</option>
  54.                         <option value="option3">option3</option>
  55.                         <option value="option4">option4</option>
  56.                         <option value="option5">option5</option>
  57.                         <option value="option6">option6</option>
  58.                         <option value="option7">option7</option>
  59.                         <option value="option8">option8</option>
  60.                         <option value="option9">option9</option>
  61.                         <option value="option10">option10</option>
  62.                         <option value="option11">option11</option>
  63.                         <option value="option12">option12</option>
  64.                         <option value="option13">option13</option>
  65.                         <option value="option14">option14</option>
  66.                         <option value="option15">option15</option>
  67.                     </select>
  68.                 </td>
  69.     </body>
  70. </html>
Regards
Ramanan Kalirajan
May 20 '09 #2

100+
P: 130
sel.options[i].selected = true;
this might work, :)
i will try it when i will get to the office.
thanks
not sure why i missed it
May 20 '09 #3

RamananKalirajan
100+
P: 607
k try it out...

Regards
Ramanan Kalirajan
May 20 '09 #4

100+
P: 130
it works
thanks Ramanan Kalirajan
May 20 '09 #5

RamananKalirajan
100+
P: 607
You are welcome. If u struck with any doubts post it out.

Regards
Ramanan Kalirajan
May 20 '09 #6

RamananKalirajan
100+
P: 607
sorry.. wrongly posted...
May 20 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.