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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML Question

Status
Not open for further replies.

orangecuse

IS-IT--Management
Jan 14, 2005
1
US
Hello, I would like to introduce myself by asking a question. It has been a while since I have done any programming until just recently. Here is my situation...

I am working on some code where I ask the user to enter their age into a text box. The next question asks whether they are male or female(radio button style). Now the key is that when the user clicks 'Male' or 'Female' their selection will be entered into the text box, following their Age they entered. Now my problem is, say I enter the age 23 and click on Male. The text box will output "23, Male". Now that is perfectly fine, but when I change my selection from Male to Female, the text you will see is "23, Male, Female" instead of just "23, Female"

I can't seem to get rid of this problem.

Hopefully that made sense. If you don't understand, you can copy my code and go to and enter the data to see for yourself.

Here is my code:

<form name="description">

Age:
<input id="text" name="text" type="text" >

<br><br><br>

Male:
<input type="radio" name="Sex" value=", male"
onclick="(text.value=text.value+this.value)">

<br>

Female:
<input type="radio" name="Sex" value=", female"
onclick="(text.value=text.value+this.value)">

</form>


Thanks in advance.
 
You can try:

onclick="text.value=parseInt(text.value)+ ', ' + this.value">

That should strip off the numbers at the beginning and ignore anything after that.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top