Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Thanked 0 Times in 0 Posts

    newbie needing to set value of hidden field

    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:

    <SCRIPT LANGUAGE="JavaScript">

    <!-- 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();

    <SCRIPT LANGUAGE="JavaScript">

    <!-- 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"

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Near Chicago, IL, USA
    Thanked 32 Times in 31 Posts

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

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts