javascript set hidden fields and post form!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dasien
    New Member
    • Apr 2007
    • 2

    javascript set hidden fields and post form!

    right off the bat - im a javascript noob so please forgive the question. im sure it is some stupid bit of syntax that i am missing, but im a middle tier developer trying to help out a friend!

    so what im trying to do is post some form data from a javascript function that gets called from an anchor tag.. here are the relevant parts of the page code.

    <html>
    <head>
    <script language="JavaS cript">
    function setItemDetails( action,id,qty)
    {
    document.myform .pageAction.val ue = action;
    document.myform .itemId.value = id;
    document.myform .itemQty.value = qty;
    document.myform .submit();
    }

    </head>
    <body>
    <form name="myform" action="http://myserver.com/cart.php" method="post">
    <input type="hidden" name="pageActio n" value="0" />
    <input type="hidden" name="itemId" value="0" />
    <input type="hidden" name="itemQty" value="0" />

    <a href="javascrip t:setItemDetail s('add_item',12 ,1)">Blah</a>
    </form>
    </body>
    </html>

    The idea was that the 'cart.php' page would get the POSTed data and use it, but i cant get the javascript function to fire. when i put "alert('test'); " in the href of the anchor tag it works, but for some reason it wont call the javascript function i have.

    any help would be appreciated.
  • dasien
    New Member
    • Apr 2007
    • 2

    #2
    sorry - after reading that post this morning, i realized i forgot the </script> tag. it is there is the code, but i didnt copy it to this message.

    Any ideas on what else it could be would be helpful!

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      It works fine in Firefox. Which browser are you using?

      Comment

      • iam_clint
        Recognized Expert Top Contributor
        • Jul 2006
        • 1207

        #4
        Code:
        <html>
        <head>
        <script language="JavaScript">
        function setItemDetails(action,id,qty)
        {
        alert("test");
        document.myform.pageAction.value = action;
        document.myform.itemId.value = id;
        document.myform.itemQty.value = qty;
        document.myform.submit();
        }
        </script>
        </head>
        <body>
        <form name="myform" action="[url="http://myserver.com/cart.php"]http://myserver.com/cart.php[/url]" method="post">
        <input type="hidden" name="pageAction" value="0" />
        <input type="hidden" name="itemId" value="0" />
        <input type="hidden" name="itemQty" value="0" />
        
        <a href="javascript:setItemDetails('add_item',12,1)">Blah</a>
        </form>
        </body>
        </html>
        worked fine in IE6

        Comment

        Working...