I'm trying to figure out how to Pass a Variable in a Javascript Form and be able to output it in PHP. This is what I have so far and it doesn't work. It must be a text link with multiple submit options.

<form name="theForm" action=<? echo $PHP_SELF; ?>>  	

<a href="javascript:document.theForm.submit(this.theForm.temp=1);">Submit</a>

<a href="javascript:document.theForm.submit(this.theForm.temp=2);">Submit 2</a>

</form>      


<?  	
if (isset($temp))
echo $temp;  
?>

Thanks for helping.

    This may be a good read to consider when doing this project.

    http://www.devarticles.com/art/1/553

    It is generally accepted that using javascript to submit forms can get pretty messy pretty quickly. If you intend to use this only for yourself or as a learning project of some sort you should be fine though.

    <?
    print $temp;
    ?>
    <head>
    <script>
    function submit_me(form,val)
    {
      form.temp.value = val;
      form.submit();
    }
    </script>
    </head>
    <body>
    <form name=test action=<?=$PHP_SELF?>>
    <input type=hidden name=temp>
    <input type=button onclick=submit_me(test,"boo") value=Submit1>
    <a href=javascript:submit_me(test,"Boo2")>Submit2</a>
    </body>
    

    It is worth noting that is most likely not cross-browser compatiable.

    -Kaz

      -Kaz

      Point taken with the article, thanks for your help.

        Write a Reply...