Inserting variable into hidden input

Discussion in 'Javascript' started by Navillus, Mar 6, 2006.

  1. Navillus

    Navillus Guest

    Hi all,

    I'm trying to insert a javascript variable into a hidden input form
    field. Here's what it looks like:

    <form name="loginForm"
    action="scripts/wgate/ziac_login/!?~language=EN">
    <input type="hidden" name="pss" value="`G_NEW_PASSWORD.value`">
    <input type="hidden" name="usr" value="">
    <input type="submit" value="Please Click Here to Continue">
    </form>

    and then later down the page I try to reassign "usr" like this:

    <script>
    var allcookies = document.cookie;
    var position = allcookies.indexOf("user=");
    var start = position + 5;
    var end = allcookies.indexOf(";", start);
    if (end == -1) end = allcookies.length;
    var valueofuser = allcookies.substring(start, end);
    valueofuser = unescape (valueofuser);
    document.write(valueofuser);
    document.loginForm.usr.value = valueofuser;
    </script>

    I can see it is printing out document.write(valueofuser) correctly, so
    I know it is grabbing the user name. But it doesn't seem to want to
    insert it into the form on the next line. Any suggestions?
    Navillus, Mar 6, 2006
    #1
    1. Advertising

  2. Navillus

    Navillus Guest

    Navillus wrote:
    > Hi all,
    >
    > I'm trying to insert a javascript variable into a hidden input form
    > field. Here's what it looks like:
    >
    > <form name="loginForm"
    > action="scripts/wgate/ziac_login/!?~language=EN">
    > <input type="hidden" name="pss" value="`G_NEW_PASSWORD.value`">
    > <input type="hidden" name="usr" value="">
    > <input type="submit" value="Please Click Here to Continue">
    > </form>
    >
    > and then later down the page I try to reassign "usr" like this:
    >
    > <script>
    > var allcookies = document.cookie;
    > var position = allcookies.indexOf("user=");
    > var start = position + 5;
    > var end = allcookies.indexOf(";", start);
    > if (end == -1) end = allcookies.length;
    > var valueofuser = allcookies.substring(start, end);
    > valueofuser = unescape (valueofuser);
    > document.write(valueofuser);
    > document.loginForm.usr.value = valueofuser;
    > </script>
    >
    > I can see it is printing out document.write(valueofuser) correctly, so
    > I know it is grabbing the user name. But it doesn't seem to want to
    > insert it into the form on the next line. Any suggestions?


    anyone?
    Navillus, Mar 7, 2006
    #2
    1. Advertising

  3. Navillus

    Jonas Raoni Guest

    Navillus wrote:
    > Navillus wrote:
    >>document.loginForm.usr.value = valueofuser;
    >></script>
    >>
    >>I can see it is printing out document.write(valueofuser) correctly, so
    >>I know it is grabbing the user name. But it doesn't seem to want to
    >>insert it into the form on the next line. Any suggestions?

    >
    > anyone?


    I don't know what to say, this sentence is quite simple, there's nothing
    to find on it =]


    --
    Jonas Raoni Soares Silva
    http://www.jsfromhell.com
    Jonas Raoni, Mar 7, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wjer
    Replies:
    1
    Views:
    486
    Alvin Bruney [MVP]
    Mar 2, 2004
  2. Kim
    Replies:
    5
    Views:
    26,935
    Glytch
    Aug 4, 2009
  3. Geoff
    Replies:
    3
    Views:
    808
    Martin Honnen
    Jun 10, 2004
  4. Renie83
    Replies:
    1
    Views:
    176
    Kiran Math
    Jul 10, 2003
  5. Walter
    Replies:
    6
    Views:
    236
    Bob Barrows [MVP]
    Sep 17, 2004
Loading...

Share This Page