Brainy Parameters

[Total: 0    Average: 0/5]

This shows how to pass and accept parameters.

Body Code:

 * This script was adapted from a script written by
 * by
 * The script was commented and made to show parameters, in an effort to help
 * others better understand how it works.
 * The original script can be found on
var idx = document.URL.indexOf('?'); /* parameters on this URL? */
var params = new Array(); /* define an array */
if (idx != -1) /* if any params detected */
  /* split all the parameters as deliniated by an "&" */
  var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
  /* go through all parameters detected */
  for (var i=0; i<pairs.length; i++)
    /* grab the variable and the value */
    nameVal = pairs[i].split('=');
	params[nameVal[0]] = nameVal[1];
param1 = unescape(params["param1"]?params["param1"]:"");
param2 = unescape(params["param2"]?params["param2"]:"");
param3 = unescape(params["param3"]?params["param3"]:"");
if(param1||param2||param3)document.write("Parameters detected:");
if(param1) document.write("<BR>PARAM1="+param1);
if(param2) document.write("<BR>PARAM2="+param2);
if(param3) document.write("<BR>PARAM3="+param3);

  -- The post method must be GET for an HTML page to receive this POST.
  -- The "action" should be the name & location of this file on the web.
<form name="form1" method="get" action="search.html">
<input type="text" name="param1" value="abc">
<input type="text" name="param2" value="1000">
<input type="text" name="param3" value="S">
<input type="submit" name="Submit" value="Submit">

Times Viewed: 1

Leave a Reply

Your email address will not be published. Required fields are marked *