"vbMark" <no@email.com> wrote in message
news:Xn************************@130.133.1.4...
On my form I have a text input box.
There are also radio buttons.
I need to take the value of the input box and the value of the
selected radio button and concatenate them with a plus sign in between.
So if the input box's value is: "Hello"
and the input box's name is name=step1
and the radio button's value is: "David"
I want the output to be:
step1=Hello+David
with the plus sign between them.
How can I do this?
<form name="myForm">
<input type="text" name="myInput" value="Text"><br>
<input type="radio" name="myRadio" value="One"> 1<br>
<input type="radio" name="myRadio" value="Two"> 2<br>
<input type="radio" name="myRadio" value="Three"> 3<br>
<input type="button" value="Append input and radio"
onclick="
alert(
myFunction(
this.form.elements['myInput'],
this.form.elements['myRadio']
)
);">
</form>
<script type="text/javascript">
function myFunction(textInput, radioInput) {
var s = textInput.value;
if ('undefined' == typeof radioInput.length) {
// normalize the collection of radio buttons
// into an array if there is only one
radioInput = [ radioInput ];
}
var ii = radioInput.length;
while (ii-- > 0) {
if (radioInput[ii].checked) {
return s + '+' + radioInput[ii].value;
}
}
return s;
}
</script>
(inline JavaScript split across multiple lines for readability and to
avoid wordwrap)
--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ -
http://jibbering.com/faq