View Full Version : newbie needing to set value of hidden field

04-22-2007, 06:39 AM
so I have a form page for a cart to checkout, on the first page, I am using the form action get and the page to pass the variables in the url to...

on the next page, I have grabbing some of them using the document.indexOf function...works great just using document.write(what is returned from the indexOf function); obviously, this just outputs the value in text, however, I need to set the value of a specific hidden field on the same page/form to that of what is returned by what I described above:


<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
return params;
params = getParams();
// End -->

and here is the part that is outputting so far...for some reason, everytime I do the passing javascript function output to the value of a hidden field, I always have a lot of trouble, so hopefully I will learn it for good this time.

here is what it is doing later in the page to write the output of the function getParams();


<!-- Begin
Product = unescape(params["product1"]);
// End -->

so my hidden field is named "item_name", how do I set it's value..., the form name that it resides in is "checkout"

04-23-2007, 06:34 PM

document.forms["checkout"].elements["item_name"].value = unescape(params["product1"]);