javascript

Hi

   I have a form

<%= form_remote_tag :url => { :action => 'sd_resolution_save',                                :id => @sd_ticket.id, },%>

<table >   <tr>     <th width=""><label for="" >Resolution Code</label></th>     <td width=""><%= select( "sd_resolution", "service_desk_resolution_code_id", ServiceDeskResolutionCode.find(:all).collect {|p| [ p.name, p.id ] }) %></td>   </tr>

  <tr>     <th width=""><label for="" >Effort</label></th>

    <td><table><tr>

    <th width=""><label for="" >Hr: </label></th>     <td><%= text_field :sd_resol, "hours", "size" => 2 %></td>     <th width=""><label for="" >Min: </label></th>     <td><%= text_field :sd_resol, "minutes", "size" => 2 %></td>

    </tr></table></td>

  </tr> </table> <table>     <tr>       <td>

<button type="submit" value="save" onclick="return checkResolution(document.getElementById('sd_resolution_service_desk_resolution_code_id'),document.getElementById('sd_resol_days'),document.getElementById('sd_resol_hours'),document.getElementById('sd_resol_minutes'), 'Please Choose Resolution');">Save</button>

<%= end_form_tag %>

And javascript is

script type="text/javascript">

   function checkResolution(elem,days,hours,minutes, helperMsg)   {

      for (i=0;i<elem.length;i++)     {     if (elem.options[i].selected){       if( elem.options[i].text.toLowerCase()== "<< select any >>"){         alert(helperMsg);       elem.focus();         return false;       }      }     }     //alert(days.value);

  } </script>

HERE THE CHECKING HAPPENS BUT THE ALERT MESSAGE IS NOT PRINTED (For example if i select nothing in the select box and click ok button nothing happens).WHY?

Sijo

Nothing happens because nothing is selected and your snippet returns void which == false