javascript - html form does not respond to hitting "enter" button -
i have html
form, not sends data php file, buts sends data javascipt function.
works fine if hit "go" button, if choose , hit "enter", not work. not send data function, is.
i have made other forms same pattern, send data javascript function in same file , work . 1 refuses.
how fix this? thanks
<form id="boroughform" enctype="multipart/form-data" method="post" action="#" onsubmit="return goborough(this); return false;" > choose borough:<br/> <select name="boroughselect" id="boroughselect" > <option selected value=" ">choose...</option> //fill options results of query performed eariler - works <?php ($v=0; $v< sizeof($borough) ; $v++) {echo '"<option value="'.$bid[$v].','.$bboxa[$v].','.$bboxb[$v].','.$bboxc[$v].','.$bboxd[$v].'" >'.$borough[$v].'</option>';} ?> </select><br/> <input type="submit" value="go" name="postbor" class="formbutton"> </form> //the js function goborough(g){ var binfo=g.elements['boroughselect'].value; if(binfo!=" "){ //some cool openlayers staff here return false; } else{alert('you have not chosen borough !!! ');return false;} }
in form element (the select) try this,
onkeypress="if(event.keycode==13) {this.submit();}"
or use jquery,
$(document).ready(function() { $("input").keypress(function(event) { if (event.which == 13) { event.preventdefault(); $("#broughtform").submit(); } }); });
Comments
Post a Comment