Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display text dynamically on HTML depending on radio button

Status
Not open for further replies.

jwhite68

IS-IT--Management
Jun 14, 2007
77
BG
I have a HTML form (combined with PHP script) which presents 3 radio buttons.

When either of the first 2 radio buttons are selected, I want to display a piece of text on the form - eg. Amount : $100.

If the user selects the third radio button, I dont want to display this text.

How can I achieve this?

Code:
<td width="217"><input type="radio" id="type" name="type" checked="checked" value="single" style="width:15px">
Option 1</td>
<td>	
<input type="radio" id="type" name="type" value="multiples" style="width:15px"> Option 2 </td>
<td width="136"><input type="radio" id="type" name="type" value="multiples" style="width:15px"> Option3</td>'
</tr>
</table>
<div>
Select option
<? if  (<what do I put here?> { ?>
Amount: $100 ?>
<? } ?>

You see that I want to display the text Amount: $100, if the condition shown by <what do I put here> is true.
Can anyone advise. So, on selection of the first or second radio button, I want to display the Amount, but if the third radio button is selected I dont want to display Amount text.
 
why are you posting this in the php forum?

i would address this through javascript.
 
As Jpadie points out this is something PHP would not be able to do unless you submit the form, and look at the values passed. Since I suspect you don't want to do that, but rather show the values immediately upon selecting the radio button, it would then be a Javascript issue. Very simple one, but Javascript nonetheless.


try the forum here for specifics on how to do it:
forum216


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
If you want to show/hide the text as the button is clicked, this is a JS matter. If you want to show/omit the text as you process a submitted form, this is a PHP matter.

The JS method is very simple - You need to add something like
<div id="showme"></div> where you intend to show/hide the $100 string. Add onClick="ShowHide(this.value);" to your input tags for the radio button.

Write a javascript and define function:
Code:
<script>
function ShowHide(value) {
if (value == 1) document.getElementById('showme').innerHTML='$100.00';
if (value == 2) document.getElementById('showme').innerHTML='$200.00';
if (value == 3) document.getElementById('showme').innerHTML='';
}
</script>

As previously mentioned, this sort of posting are best posted in the JS or HTML forums.

Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top