HTML Form question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vbMark

    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+Dav id

    with the plus sign between them.

    How can I do this?

    Thanks!
  • Grant Wagner

    #2
    Re: HTML Form question

    "vbMark" <no@email.com > wrote in message
    news:Xns95C26EE 0C1775noemailco m@130.133.1.4.. .[color=blue]
    > 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[/color]
    selected[color=blue]
    > 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+Dav id
    >
    > with the plus sign between them.
    >
    > How can I do this?[/color]

    <form name="myForm">
    <input type="text" name="myInput" value="Text"><b r>
    <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.eleme nts['myInput'],
    this.form.eleme nts['myRadio']
    )
    );">
    </form>
    <script type="text/javascript">
    function myFunction(text Input, radioInput) {
    var s = textInput.value ;

    if ('undefined' == typeof radioInput.leng th) {
    // normalize the collection of radio buttons
    // into an array if there is only one
    radioInput = [ radioInput ];
    }

    var ii = radioInput.leng th;
    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 <gwagner@agrico reunited.com>
    comp.lang.javas cript FAQ - http://jibbering.com/faq


    Comment

    Working...