PDA

View Full Version : Urgent: "?variable = value" Problems


abbraciatutto
07-10-2004, 12:10 PM
Hey guys, first post.

I am having trouble with my form. I have it where the URL contains information:
server.com/file.html?name=george
I am using FrontPage and know HTML, the script I am using is from here: http://hotwired.lycos.com/webmonkey/reference/javascript_code_library/parse_get/?tw=reference&category=forms_data.

How do I get it into a hidden field of the form?

P.S. I have already tried this:
<input type="hidden" name="name" value="$you">

agent002
07-10-2004, 12:19 PM
Try this script:
<script type="text/javascript">
//<![CDATA[

var query = location.href.substring((location.href.indexOf('?')+1), location.href.length);
var querysplit = query.split('&');
query = new Array();
for(var i = 0; i < querysplit.length; i++){
var namevalue = querysplit[i].split('=');
query[namevalue[0]] = unescape(namevalue[1]);
}

window.onload = function(){
// populate fields here:

document.getElementById('firstname').setAttribute('value', query['firstname']);
document.getElementById('lastname').setAttribute('value', query['lastname']);
}

//]]>
</script>
along with this HTML:
First name: <input type="text" id="firstname"><br>
Last name: <input type="text" id="lastname">
and this query string:
filename.html?firstname=Jere&lastname=Purmonen
Although, a server side script is the best way to parse a query string.

abbraciatutto
07-10-2004, 03:41 PM
that worked! thank you so much!