471,091 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,091 software developers and data experts.

HTML Form question

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?

Thanks!
Jul 23 '05 #1
1 1161
"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
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by sumithradevi | last post: by
2 posts views Thread by Mark Watkins | last post: by
5 posts views Thread by Richard Cornford | last post: by
16 posts views Thread by Philippe C. Martin | last post: by
11 posts views Thread by VB Programmer | last post: by
4 posts views Thread by Chris | last post: by
1 post views Thread by eunever32 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.