0

I'm a newbie at this sort of thing and I need some specific help. I'm passing two fields in a URL from a CGI script to an HTML form. I need to print the two values in the form I'm passing them to. The URL looks like this:

  http://www.nanr.org/?LN=Wilson&FN=John

I need to print the values of LN and FN in my form. The HTML code currently looks like this:

<input type="text" size="15" style="width:40" name ="LastName" value="">&nbsp;
<input type="text" size="15" style="width:40" name ="FirstName" value="">

How do I do this?

I have included the following code in my HTML Form page:

</script> 

<script type="text/javascript">

function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
    results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

</script>

hunch_hunch
  • 2,283
  • 1
  • 21
  • 26
Hamruniz
  • 23
  • 3

1 Answers1

0

You can use location.search Try this:

var url = location.search; // ?LN=Wilson&FN=John

var LN = String(url.substring(url.indexOf("LN=")+1, url.substring(url.indexOf("FN"))); // LN=Wilson

var FN= String(url.substring(url.indexOf("FN=")+1, url.length)); // FN=John

And then display them in the html like this:

input type="text" size="15" style="width:40" name ="LastName" value="<script>out.print(LN)</script>">&nbsp;
<input type="text" size="15" style="width:40" name ="FirstName" value="<script>out.print(FN)</script>">

Or maybe instead you could use ${LN} and ${FN} but i think thats only with java attributes.

PT_C
  • 1,178
  • 5
  • 24
  • 57