Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Mar 2003
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts

    parsing form data

    doing this client side, I have form 1 sending its value to form 2. On form 2 i have,
    <head>
    <script type="text/javascript">
    <!-- Begin

    window.onload = updateRunningScore;
    function updateRunningScore(){
    var sStr = document.location.search;
    val = parseInt(sStr.substring(sStr.indexOf("=")+1,sStr.length));
    document.getElementById("currentScore").innerHTML = "Your score up to this point is = "+((!isNaN(val))?val:0);
    document.f2.age.value = val;
    }

    // End -->
    </script>

    <body>
    <input type="hidden" name="age" value="">

    so my form 3 url after form 2 submits is Occupational_Demand.htm?age=10&edu=20 ///exactly what i want it to be, 10 and 20 are the choosen values.

    now on submit of form 3 i'm trying to have the form4 url just extend the string to include the form3 value pair, like so:
    Guaran.htm?age=10&edu=20&occ=14
    but i keep losing it:
    Guaran.htm?age=10&edu=NaN&occ=14

    would appreciate some direction, thanks

    this is what incorrectly have:
    <script type="text/javascript">
    <!-- Begin
    window.onload = updateRunningScore;
    function updateRunningScore(){
    var sStr = document.location.search;
    val = parseInt(sStr.substring(sStr.indexOf("=")+1,sStr.length));
    va2 = parseInt(sStr.substring(sStr.indexOf("edu=")+1,sStr.length));
    document.getElementById("currentScore").innerHTML = "Your score up to this point is = "+((!isNaN(val))?val:0);
    document.f3.age.value = val;
    document.f3.edu.value = va2;
    }
    // End -->
    </script>
    </head>
    <body>
    <input type="hidden" name="age" value="">
    <input type="hidden" name="edu" value="">

    BTW, i'm working of the addition of the string values for the "currentScore".

  • #2
    Regular Coder
    Join Date
    Mar 2003
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool

    figured it out:

    va2 = parseInt(sStr.substring(sStr.indexOf("edu=")+4,sStr.length));

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by havey
    figured it out:

    va2 = parseInt(sStr.substring(sStr.indexOf("edu=")+4,sStr.length),10);
    Add the part in red above or your users will get strange results when they enter numbers with leading zeroes (without the "radix" specified for base 10, a leading zero will cause parseInt to assume the user entered an Octal number).
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #4
    Regular Coder
    Join Date
    Mar 2003
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I though that maybe your suggestion, Roy, would solve my problem, thanks for the tip, this is my problem:

    this funny url from form 5 to 6:
    Experience.htm?age=10&edu=20&occ=NaN&gua=NaN&reg=5

    the form preceeding it is fine:
    Development.htm?age=10&edu=20&occ=4&gua=10

    why the NaNs???

    this is Development.htm:
    <head>
    <script type="text/javascript">
    <!-- Begin
    window.onload = updateRunningScore;
    function updateRunningScore(){

    var sStr = document.location.search;
    val = parseInt(sStr.substring(sStr.indexOf("=")+1,sStr.length));
    va2 = parseInt(sStr.substring(sStr.indexOf("edu=")+4,sStr.length));
    va3 = parseInt(sStr.substring(sStr.indexOf("occ=")+5,sStr.length));
    va4 = parseInt(sStr.substring(sStr.indexOf("gua=")+6,sStr.length));

    document.f5.age.value = val;
    document.f5.edu.value = va2;
    document.f5.occ.value = va3;
    document.f5.gua.value = va4;

    document.getElementById("currentScore").innerHTML = "Your score up to this point is = "+((!isNaN(val))?val:0);
    }
    // End -->
    </script>

    </head><body>

    <form name="f5" method="GET" action="Work_Experience.htm">
    <input type="hidden" name="age" value="">
    <input type="hidden" name="edu" value="">
    <input type="hidden" name="occ" value="">
    <input type="hidden" name="gua" value="">

    and this is Experience.htm:

    <head>
    window.onload = updateRunningScore;
    function updateRunningScore(){

    var sStr = document.location.search;
    val = parseInt(sStr.substring(sStr.indexOf("=")+1,sStr.length));
    va2 = parseInt(sStr.substring(sStr.indexOf("edu=")+4,sStr.length));
    va3 = parseInt(sStr.substring(sStr.indexOf("occ=")+5,sStr.length));
    va4 = parseInt(sStr.substring(sStr.indexOf("gua=")+6,sStr.length));
    va5 = parseInt(sStr.substring(sStr.indexOf("reg=")+7,sStr.length));

    document.f6.age.value = val;
    document.f6.edu.value = va2;
    document.f6.occ.value = va3;
    document.f6.gua.value = va4;
    document.f6.reg.value = va5;
    }

    </head>

    <body>
    <form name="f6" method"GET" action="Language.htm">
    <input type="hidden" name="age" value="">
    <input type="hidden" name="edu" value="">
    <input type="hidden" name="occ" value="">
    <input type="hidden" name="gua" value="">
    <input type="hidden" name="reg" value="">


  •  

    Posting Permissions

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