Monday 15 July 2013

html - Different action on submit a form depending on input value -


I have an original HTML form with a search box if the user searches for a search or search A-B, Need to redirect to two different places (the URL is formatted differently)

How would you suggest that I do this?

  & lt; Form name = "ajaxsearchfrm" action = "url1 or url2" method = "get" & gt; & Lt; Input type = "text" id = "searchText" name = "searchText" style = "width: 200px;" Onkeyup = "searchSuggest ();" Auto complete = "off" & gt; & Nbsp; & Nbsp; & Lt; Input type = "submit" value = "search" style = "background-color: #fff; font-family: vardana, aerial, helvetica; color: black; font-size: 10px;" / & Gt; & Lt; Div id = "formSuggestLayer" & gt; & Lt; / Div & gt; & Lt; / Form & gt;    

You will want to use JavaScript to evaluate the contents of the text box Based on this, change the form's action and then submit the form through javascript. You have to change your submit button on a regular button with an on-call event.

Javascript:

  function EvaluateForm () {if (document.getElementById ('SearchText'). Value == 'A') {// Submit to a document . JajSearchFrm.action = "myurlA.com"; } Else {// submit to b document.ajaxSearchFrm.action = "myurlB.com"; } Document.forms ["ajaxsearchfram"]. Submit (); return false; }   

HTML:

  & lt; Form name = "ajax search frame" action = "" method = "received" & gt; & Lt; Input type = "text" id = "searchText" name = "searchText" style = "width: 200px;" & Gt; & Amp; Nbsp; & Amp; Nbsp; & Lt; Input type = "button" value = "search" onClick = "return evaluation ();" / & Gt; & Lt; Div id = "formSuggestLayer" & gt; & Lt; / Div & gt; & Lt; / Form & gt;    

No comments:

Post a Comment