help me to Reset select tag with multiple options in IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • helplakshmi
    New Member
    • Dec 2009
    • 14

    #1

    help me to Reset select tag with multiple options in IE

    Hi All,

    I am new to php. The form that i am designing has few input input fields with submit and reset button. The functionality of submit and reset are working properly till now.

    My form
    Code:
      
     <form name="search" id="search" action= "search.php" method = "post" onreset="formReset(this);return false;">
    
     <table cellspacing="1" cellpadding="1" >
                <tr>  <!-- Input field for responsible-->
                    <td width="200" > <b> Responsible: </b> </td>
                         <td>  <select name="responsible[]" 
                          id="responsible[]"  multiple="multiple">
                                     <option value="" > </option>
                                    <option value="ALL"> ALL </option>
                                    <?php
                                    $subject_set = get_all_subjects();
                                    $subject_count = odbc_num_rows($subject_set);
                                    while ($subject = odbc_fetch_array($subject_set)) {
                                        echo "<option value=\"{$subject['menu_name']}\"";
                                        if($responsible) {if(in_array($subject['menu_name'],$responsible)) { echo " selected"; }}
                                        echo ">{$subject['menu_name']}</option>";
                                    }
                                    ?>
                                </select>
                            </td>
                        </tr>
                  </tbody>
               </table>          
            </form>
    and javascript - 'formReset' that i am calling was

    Code:
     function formReset(frm) {
        for(var i=0;i<frm.elements.length;i++){
            if(!(frm.elements[i].type && frm.elements[i].type == "submit") &&
                !(frm.elements[i].type && frm.elements[i].type == "reset") &&
                !(frm.elements[i].type && frm.elements[i].type == "button"))
                frm.elements[i].value = "";
            if (frm.elements[i].type == 'radio' && frm.elements[i].checked == true) {
                frm.elements[i].checked = false;
             
            }
        }
    It is working perfectly. The only change i made in the form was to add multiple="multi ple" feature for the select tag. Now on click reset it is restoring the previous values. It is not resetting the selected values. I checked the same in Firefox it working as desired(reset the multiple selected values) but not in IE. I have been banging my head since morning.I have a deliverable for tomorrow. So please help me
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    Could you post the HTML that is being generated and sent to the browser, rather than the PHP code? We can't really recreate the problem using the PHP code alone, because we don't have the options your code is using.

    P.S.
    Seeing as this is more about the HTML/JavaScript then the PHP code, I've moved the thread to the JavaScript forums.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      With the multiple select element, you will need to loop over the options and set each one to false. So in your reset function, check for the select type and code accordingly.

      Comment

      Working...