Click here to Skip to main content
16,008,490 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
I would like to know how to pass parameter/value using location.href
this is my code pleas say is correct or no



XML
<script >

           function btnExternalPayGhest_Click(id) {


               if (id == 190) {





                   document.location.href="/KB/answers/frmInstallmentPayment.aspx" + GhestCompanyID, ExternalGhestID, ExternalCellPhone;

               }

               else if (id == 240) {

                   document.location.href="/KB/answers/frmInstallmentPayment.aspx" + GhestCompanyID, ExternalGhestID, ExternalCellPhone;




               }

           }

       </script>
       <form name="form1">

           <input type="button" name="بررسی" value="بررسی" onclick='btnExternalPayGhest_Click()'>

       </form>
Posted

Your code doesn't make a lot of logical sense, but essentially you can set a URL with paramters like:
JavaScript
location.href = 'page.aspx?x=' + param1 + '&y=' + param2 + '&z=' + param3;

If you need to pass nonalphanumeric characters you may neeed to look into encoding [^] it.
 
Share this answer
 
href is a string that can contain an URL address wit some parameters in the format of query string...
par1=val1&par2=val2

If you have the values you can use jQuery's param[^] method to create such string from a JavaScript object easily...
JavaScript
var params = {
  "param1": GhestCompanyID, 
  "param2": ExternalGhestID, 
  "param3": ExternalCellPhone
}

document.location.href = "frmInstallmentPayment.aspx?" + $.param( params );
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900