[thelist] How do I submit a single form thru either of two links using JavaScript AND pass a hidden value depending on the link?

Ivo P ipletikosic at gmail.com
Wed Apr 20 11:35:10 CDT 2005


Hello friends,

I have a form that is submitted using JavaScript. There are two links
that can submit the form but I want an additional hidden value
returned to the server depending on which link was clicked. Like this:

The Form:

<form name='myform1' method='post' action=CGI_URL>
    <input type='hidden' name='mode' value='1'>
    Select your platform:<br/>
    <input checked type="radio" name="type" value="1">Windows<br/>
    <input checked type="radio" name="type" value="2">Mac<br/>
    <input checked type="radio" name="type" value="3">Linux<br/>
</form>

The JavaScript:

<script language="JavaScript">
<!--
document.write("<a
href='javascript:document.myform1.submit()'>Download v1.0</a>");
document.write("<br/>");
document.write("<a
href='javascript:document.myform1.submit()'>Download v1.0.1</a>");
-->
</script>

The problem:

Clicking either link should submit the form myform1 but depending on
which link was clicked an additional hidden value (say version='1.0'
or version='1.0.1') should be sent back with the form.

Any pointers on how to accomplish this?

My initial guess (I am new at this) is to include an additional hidden
field in the original form called version. When a user clicks one of
the links a function is called where it rewrites the value of the
field (document.myform1.version.value = '1.0';) and only then it
submits it.

Does this sound correct?

Thanks for the help,

I.


More information about the thelist mailing list