Products
Services
Contact Us

Scripts: Javascript :: Forms :: Library Article #21

Developer's Section

Get the Query String using Javascript
By: Erobo Team Member

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (2577)
Favorites:

Learn to get value from your variables when you submit a form using javascript

It is possible to get the query string from your forms when your form method is set to 'GET'. Use the following code:

 Code Snippet 1

<script language="Javascript">
function getQuery(thisVariable) {
 theQueryString = window.location.search.substring(1);
 variableArray = theQueryString.split("&");
 for (i=0; i < variableArray.length; i++) {
  variableRetrieved = variableArray[i].split("=");
  if (variableRetrieved[0] == thisVariable) {
   return variableRetrieved[1];
  }
 }
}
</script>


You can call the getQuery() method the following way:

 Code Snippet 2

//if the query string is:http://yoursite.com/myform?variable1=true
//mysubmission should be equal to true
var mysubmission = getQuery("variable1");
alert(mysubmission)


Finally, you can also retrieve the query string from the parent frame like this:

 Code Snippet 3

function getCriteria(thisVariable) { 
 theQueryString = window.parent.location.search.substring(1); 
 variableArray = theQueryString.split("&"); 
 for (i=0; i < variableArray.length; i++) { 
  variableRetrieved = variableArray[i].split("="); 
  if (variableRetrieved[0] == thisVariable) { 
   return variableRetrieved[1]; 
  } 
 }
 
 return null;
}



See other Scripts in Forms

 

Submit Your Scripts:

If you would like to have your Javascripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Email:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]