javascript - Firefox html5 validation anomaly with dynamic select options -


here simple html5 form 2 select controls. changing selection in first select generates new list of options second select. both have "required" attribute, , selected blank option. odd bit red validation outline around second select control, without submitting form. no tool-tip error message, outline.

<!doctype html> <body>  <script language="javascript" type="text/javascript">  function select_update(srcctrlid, dstctrlid)     {     //alert(srcctrlid+','+dstctrlid+','+url);     sel1 = document.getelementbyid(srcctrlid);     srcvalue = sel1.value;      sel2 = document.getelementbyid(dstctrlid);      while(sel2.options.length > 0) {         sel2.remove(0);         }      if (srcvalue == '')         {         var ooption = new option( '(no matches)', '', true, true );         sel2.add(ooption);         }     else         {         var ooption = new option( '-- select2 --', '', true, true );         sel2.add(ooption);          for(i=1; i<=5; ++i)             {             v = srcvalue * 10 + i;             s = 'select2, option'+v;             var ooption = new option( s, v, false, false );             sel2.add(ooption);             }         }     }  function jsvalidatepage1()     {     alert('onsubmit');     return false;     return true;     }  </script>  <form onsubmit="return jsvalidatepage1();">  <select name="select1" id="select1" size="1" onchange="select_update('select1','select2');" required> <option value="" selected="selected">-- select1 --</option> <option value="1">select1, option1</option> <option value="2">select1, option2</option> <option value="3">select1, option3</option> <option value="4">select1, option4</option> <option value="5">select1, option5</option> </select> <br><br> <select name="select2" id="select2" size="1" required> <option value="" selected="selected">-- select2 --</option> <option value='' disabled>(empty)</option> </select> <br><br> <select name="select3" id="select3" size="1" required> <option value="" selected="selected">-- select3 --</option> <option value="1">select3, option1</option> <option value="2">select3, option2</option> <option value="3">select3, option3</option> <option value="4">select3, option4</option> <option value="5">select3, option5</option> </select> <br><br> <input type="text" name="dummy" value="" required=""> <br><br> <input type="submit"> </form>  </html> 

fiddle here: https://jsfiddle.net/afg57g0u/1/

run code, , select option in first select control. second lights red immediately, other required controls not, it's not validating whole form, second select control (sort-of).

this happens in firefox 36.0.4. not happen on ie 11.0.17, opera 28.0, chrome 41.0.2272.101, or safari 5.1.7 (duh). (on win8 box)

i can find no other mention online of similar problem. have tried numerous approaches disable or work-around problem, no luck. have ideas? firefox bug?

remove required attribute select before changing options. add mousedown listener submit button , set required attribute on select then. id given submit button:

submit = document.getelementbyid('submitbtn');  submit.addeventlistener('mousedown',function()    {      sel2.setattribute('required',true); }); 

working fiddle: https://jsfiddle.net/afg57g0u/2/

note, should add listener keydown keycode enter button, , touchstart touch devices. should call same function mousedown event.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -