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
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Issues with passing variables through a form

    I'm still having a bit of trouble with a script someone helped me with. After you change the value of x on the page I need to be able to hit submit it so a php script can then insert the information into my database, but the value doesn't seem to pass through when I submit it. I'm not too skilled with javascript so any help is appreciated.
    Thanks

    <script type="text/javascript">
    function updateX(id,number){
    var element = document.getElementById(id);
    element.innerHTML = element.innerHTML/1+number;
    }
    </script>
    </head>

    <body>
    <form method="get" action"test.html" name="myform">
    <img style="cursor:pointer;border:none" src="minus.gif" onclick="updateX('x',-1)">
    <span style="width:25px;text-align:center;" id="x">6</span>
    <img style="cursor:pointer;border:none" src="plus.gif" onclick="updateX('x',+1)">
    <input type="hidden" name="x">
    <input type="submit" name="submit" value="submit">
    </form>

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    change this:

    <input type="hidden" name="x">

    to this:

    <input type="hidden" name="x" id="x" value="">

    change this:

    action"test.html"

    to this:

    action="test.html"

    change this:

    updateX('x',+1)

    to this:

    updateX('x',1)

    and underneath this:

    element.innerHTML = element.innerHTML/1+number;

    add this:

    document.getElementById("x").value=element.innerHTML/1+number;


    should work...
    Last edited by Spudhead; 01-05-2005 at 04:51 PM.

  • #3
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    In fact, screw it. There's too many errors in your code mate

    Try this:

    <html>
    <head>
    <title>Untitled</title>

    <script type="text/javascript">
    function updateX(number){
    var elementvalue=parseInt(document.getElementById('x').innerHTML);
    var newvalue = elementvalue+number;
    document.getElementById('x').innerHTML = newvalue;
    document.getElementById('hdn_x').value=newvalue;
    }
    </script>

    </head>

    <body>
    <form method="get" action="test.html" name="myform">
    <img style="cursorointer;border:none" src="minus.gif" onclick="updateX(-1)">
    <span style="width:25px;text-align:center;" id="x">6</span>
    <img style="cursorointer;border:none" src="plus.gif" onclick="updateX(1)">
    <input type="hidden" name="hdn_x" id="hdn_x">
    <input type="submit" name="submit" value="submit">
    </form>

    </body>
    </html>

  • #4
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It worked. Thanks for the help.


  •  

    Posting Permissions

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