JavaScript: Methods for setting URL parameters, suitable for multi-criteria queries

Source: Internet
Author: User

applicable scenario : Multi-condition query case, as shown in:

By setting the URL parameter, combined with the Rul parameter set by the data source control, a simple multi-criteria query can be made.

JavaScript functions:

<mce:script type="Text/javascript"><!--//methods for setting URL parametersfunction Setparmsvalue (parms, parmsvalue) {varUrlstrings =document.            URL; varargs =geturlparms (); varValues =Args[parms]; //If the parameter does not exist, add the parameter          if(Values = =undefined) {                varquery = Location.search.substring (1);//Get query string//If there are already parameters in the URL, the additional parameters              if(query) {urlstrings+= ("&"+ Parms +"="+parmsvalue); }                Else{urlstrings+= ("?"+ Parms +"="+ Parmsvalue);//Add the first parameter to a URL} window.location=urlstrings; }            Else{window.location= Updateparms (parms, Parmsvalue);//Modifying Parameters          }        }          //Modify URL parameter, parms: Parameter name, Parmsvalue: Parameter value, return: Modified URLfunction Updateparms (parms, parmsvalue) {varNewurlparms =""; varNewurlbase = location.href.substring (0, Location.href.indexOf ("?") +1);//intercept the URL in front of the query string          varquery = Location.search.substring (1);//Get query string          varPairs = Query.split ("&");//Break at comma           for(vari =0; i < pairs.length; i++) {                varpos = Pairs[i].indexof ('=');//Find Name=value              if(pos = =-1)Continue;//If you don't find it, skip it.              varArgname = pairs[i].substring (0, POS);//Extract Name              varValue = pairs[i].substring (pos +1);//Extract Value//If you find the parameter that you want to modify              if(FindText (Argname, parms)) {newurlparms= Newurlparms + (argname +"="+ Parmsvalue +"&"); }                Else{newurlparms+ = (Argname +"="+ Value +"&"); }            }            returnNewurlbase + newurlparms.substring (0, Newurlparms.length-1); }          //Auxiliary Methodsfunction FindText (urlstring, KeyWord) {returnUrlstring.tolowercase (). IndexOf (Keyword.tolowercase ())! =-1?true:false; }          //get query string parameter collectionfunction geturlparms () {varargs =NewObject (); varquery = Location.search.substring (1);//Get query string          varPairs = Query.split ("&");//Break at comma           for(vari =0; i < pairs.length; i++) {                varpos = Pairs[i].indexof ('=');//Find Name=value              if(pos = =-1)Continue;//If you don't find it, skip it.              varArgname = pairs[i].substring (0, POS);//Extract Name              varValue = pairs[i].substring (pos +1);//Extract ValueArgs[argname] = unescape (value);//Save As Property          }            returnargs; }        --></mce:script>

Test code:

<body> <input type="Button"Id="Button1"onclick="setparmsvalue (' Test1 ', ' AAA ')"Value="set URL parameters [TEST1=AAA]"/> <input type="Button"Id="Button2"onclick="setparmsvalue (' Test1 ', ' BBB ')"Value="set URL parameters [TEST1=BBB]"/> <input type="Button"Id="Button3"onclick="setparmsvalue (' Test2 ', ' AAA ')"Value="set URL parameters [TEST2=AAA]"/> <input type="Button"Id="Button4"onclick="setparmsvalue (' Test2 ', ' BBB ')"Value="set URL parameters [TEST2=BBB]"/> </body>

JavaScript: Methods for setting URL parameters, suitable for multi-criteria queries

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.