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

JAVA BEGINNER NEEDS A LITTLE HELP

Status
Not open for further replies.

ADEMAR

Programmer
Apr 20, 2002
43
US
Hello,
I have the following script in my page that takes the value of a radio button and places the value into a text box. I need to add to this script to have another selection (pairing) of radio buttons to take the result from the previous pairing, value in text box1 and place into text box2.

Code I have already:

<SCRIPT LANGUAGE=&quot;JavaScript&quot; TYPE=&quot;text/javascript&quot;>
<!--
function doText(valVar)
{
document.TestForm.FillMe.value = valVar
}
//-->
</SCRIPT>
</head>
<body>
<form name=&quot;TestForm&quot;>
500 &nbsp;<input type=&quot;radio&quot; name=&quot;Cost&quot; value=&quot;500&quot; onClick=&quot;doText(this.value)&quot;><br>
550 &nbsp;<input type=&quot;radio&quot; name=&quot;Cost&quot; value=&quot;550&quot; onClick=&quot;doText(this.value)&quot;><br><br>
<input type=&quot;text&quot; name=&quot;FillMe&quot; value=&quot;&quot;>
<form>

</body>
</html>

Example of what I need in WYSWG:

button group 1 is:
o 500
o 550

Lets say the user checks 500 button

Text Box1 now reads 500

** From here on is where I need help **
New Group Pairing of radio buttons (group 2):
o Yes
o No

If user checks Yes I need result of 1st Text Box1 from 1st group to appear in Text Box 2 (not created yet)

Any help is greatly appreciated,
Adam
email: ald@storis.com
 
Add this to the form you already have:
[tt]
<input type=&quot;radio&quot; name=&quot;question&quot; value=&quot;yes&quot; onClick=&quot;addValue()&quot;> yes
<br>
<input type=&quot;radio&quot; name=&quot;question&quot; value=&quot;no&quot;> no
<br><input type=&quot;text&quot; name=&quot;second&quot;>
[/tt]
and this to the script section:
[tt]
function addValue() {
document.TestForm.second.value = document.TestForm.FillMe.value;
}
[/tt]
Note that NAME property of the radios should be the same in order to create a group.
 
Thank you very much; I will try !!
 
Starway, thanks again for your post. I've merged in your code and it works! :) There are 2 gray areas about the overall result that I am hoping you could help with.

1.) I should have mentioned this in my primary post but I need the value of the &quot;no&quot; radio button (second grouping, second button) to be displayed its value as well in text box2. This button can be hard coded with its value.

2.) After I make a change to the first set of radio buttons the 2nd text box does not update/refresh itself with the new data. Is their any way of making this refresh after changing a radio button belonging to the 1st group of radio buttons?

Thanks again for all your help,
Adam
email: ald@storis.com
 
OK, here it is:

1. [tt]
function addValue() {
document.TestForm.second.value = document.TestForm.FillMe.value + &quot; : &quot;
+ document.TestForm.question[1].value;
}[/tt]
The values in the text box will be separated by &quot; : &quot;.
You have to access the radio button that is a member of some group as an array element:
[tt]document.formName.radioName[n][/tt]
because all radios inside one group have the same value.

2. Very simple. You wrote in your script:
[tt]document.TestForm.FillMe.value = valVar[/tt]
that the value of the 1st text box should change each time you select a radio button form the 1st group.
In order to make it change the value of the 2nd text box, you need to change the name of the text box:
[tt]document.TestForm.second.value = valVar[/tt]

But, in this case, you don't need two text boxes at all.
If you want to assign that value to both text boxes, just add another expression to your doText() function, so it will be like this:
{
1st_txtbox.value = valVar;
2nd_txtbox.value = previous_val + valVar; (or just &quot;= valVar&quot;)
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top