Passing Parameters HTML to HTML

[Total: 0    Average: 0/5]

This shows how to pass parameters from one HTML document to another, and how to read those parameters in the new HTML.

Body Code:

<form name=exf1>
P1 = <input type=text name=t1 value="parm1"><BR>
P2 = <input type=text name=t2 value="parm2"><BR>
</form>
<a href="javascript:doIt()">pass params</a>
<script type=text/javascript>
function doIt() {
  var _t1 = escape(document.exf1.t1.value);
  var _t2 = escape(document.exf1.t2.value);
  var _x = document.location.toString().indexOf("?") == -1?"?":"&";
  // if you want to use this more that just once in a row:
  //  you need to change = document.location + .. to be:
  //  = document.location.toString().substr(0,document.location.toString().indexOf("?")) + ...
  //  this will remove the parameters passed to it before adding the new parameters..
  document.location = document.location + _x + "t1="+_t1+"&t2="+_t2;
}
var _p,_q,_n;
_p = document.location.toString();
_q = _p.indexOf("t1=");
if (_q != -1 ) {
  _n = _p.substr(_q+3,_p.length);
  if (_n.indexOf("&") != -1) {
    _n = _n.substr(0,_n.indexOf("&"));
  }
  document.exf1.t1.value = unescape(_n);
}
_p = document.location.toString();
_q = _p.indexOf("t2=");
if (_q != -1 ) {
  _n = _p.substr(_q+3,_p.length);
  if (_n.indexOf("&") != -1) {
    _n = _n.substr(0,_n.indexOf("&"));
  }
  document.exf1.t2.value = unescape(_n);
}
</script>

Times Viewed: 0

Leave a Reply

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