How to stop a webpage startup form before transferring?
Problem:
When I enter fields in an HTML website form, I'm running an onSumit function at the end.
However, after editing the method, a submit submit of the form is always automatically executed.
You have to interrupt the onsubmit somehow.
Solution:
One enters in the onsubmit-function a false value.
This false value can be used as the return value of a javascript-function
onsubmit="return send_Search()" |
In onsubmit enter a return false value
<form id="frmList" style="display:inline-block" onsubmit="return send_Search()"> <input id="tbxSearch" name="tbxSearch" value="@sSearch" style="width:200px;color:black"> Ort: <input id="tbxOrt" name="tbxOrt" value="@sOrt" style="width:80px;color:black " /> <button type="submit" value="send">Send</button> </form>
|
The called function executes processes and ends the function with return false
//< send > window.location.href = sURL; //goto new URL return false; //stop send form //</ send > |
example
Complete javascript funtion
//============< Layout >============ //*layout Menu, Search-Input and Footer
function send_Search() { //------< send_Search() >------ var form = document.getElementById("frmSearch"); var input_Search = document.getElementById("tbxSearch"); var input_Ort = document.getElementById("tbxOrt"); var sSearch = input_Search.value; var sOrt = input_Ort.value;
var sURL = "/projects"; var sQuery = ""; if (sSearch != "") { sSearch = encodeURI(sSearch); //for c# sQuery = sQuery + "&s=" + sSearch; }
if (sOrt != "") { sOrt = encodeURI(sOrt); sQuery = sQuery + "&o=" + sOrt; } if (sQuery != "") { sQuery = sQuery.substr(1); sURL = sURL + "?" + sQuery; }
//< send > window.location.href = sURL; //goto new URL return false; //stop send form //</ send > //------</ send_Search() >------ }
//============</ Layout >============
|