I have an email program that automatically sends whatever fields are on a form, and I need to dynamically change the value of one of the hidden fields in a form based on the selection of a radio button. This needs to be set before the form is submitted. Can it be done with the onClick somehow in php?

<form action="email.pl" method="post">
e-mail address:<br>
<input type="text" name="email" size="32" maxlength="64">
<DD><input type="radio" name="action" value="Subscribe" id="Subscribe" checked>
<label for="Subscribe">Subscribe</label>
<DD><input type="radio" name="action" value="Remove" id="Remove">
<label for="Remove">Unsubscribe</label>
<input type="hidden" name="Msg" value="dynamic value">
<BR><input type="submit" value="Submit">
</form>

    Done with PHP before submitting? No. PHP has no idea what radio button is chosen until you tell it (submit the form). You can code the next page to choose what the value is based on the radio button. Beyond that, you'd need Javascript.

      as LordShryku said you will definetly need Javascript.
      I would suggest using the getElementByTag() function inside the onClick.

      EDIT: There is one problem, getElementbyTag only works on quite recent browsers, so it will not work for some users.

        Write a Reply...