www.webdeveloper.com
Results 1 to 3 of 3

Thread: set textbox value to selected radio button one

  1. #1
    Join Date
    Mar 2011
    Posts
    4

    Post set textbox value to selected radio button one

    Hey Guys,

    I have three radio buttons and one textbox. If user select one of those radio buttons and type something in the textbox which is the value of the textbox, I want that value to be the value of the radio button that is selected, now the user may enter the value into the text box and then select the radio button or first select a radio button then enter something to the textbox, anyway the value of radio button should be equal to textbox value that user enter!


    additional explanation :

    (I have three radio buttons and one text box in a form which is for shipment tracking, now what I need is when I type something in that textbox (which is the value) and select one of those three radio buttons then clicking on go (submit) textbox value and selected radio button value will pass through URL (get method) on the result page I see two different value, one for my textbox and one for the selected radio button ,now I want that selected radio button value be as exact as the textbox one so the selected radio button value should follow the textbox value and both be equal so for example when I type some number like 870 in the textbox and select one of those three radio buttons an submit the form the result page URL have to show the radio button value 870 as the textbox is.)


    The important point is changing value is just an option I mean it's not necessary that radio button values being changed it could be empty of any value and then fill by textbox value. I just want the selected radio button value ( One of those three radio buttons which user selected ) to be the exact same as user typed in textbox.


    This could be done with js or something !


    My Form code :

    <form id="Shipment" name="Shipment" method="get" action="tope_results.asp" class="zero" onSubmit="popupform(this, 'join')">

    <input type="radio" name="SrchQuery" id="n4" value="CNTR" />

    <input type="radio" name="SrchQuery" id="n2" value="BLNo" />

    <input type="radio" name="SrchQuery" id="n3" value="Fln"/>

    <input name="n1" type="text" class="Textbox" id="n1" size="29" onfocus="javascript:if(this.value=='Shipment Tracking ...') {this.value='';}" onblur="javascript:if(this.value=='') {this.value='Shipment Tracking ...'}" value="Shipment Tracking ..."/>

    <input name="button" type="submit" class="SHN" id="button" value="GO"/>

    </form>


    thanks so much.

  2. #2
    Join Date
    Feb 2011
    Location
    israel
    Posts
    157
    html:
    HTML Code:
    <form id="Shipment" name="Shipment" method="get" action="tope_results.asp" class="zero" onSubmit="popupform(this, 'join')">
        
        <input type="radio" name="SrchQuery" id="n4" value="CNTR" onclick="ship('n4')" />
        
        <input type="radio" name="SrchQuery" id="n2" value="BLNo" onclick="ship('n2')" />
        
        <input type="radio" name="SrchQuery" id="n3" value="Fln" onclick="ship('n3')"/>
        
        <input name="n1" type="text" class="Textbox" id="n1" size="29" onfocus="javascript:if(this.value=='Shipment Tracking ...') {this.value='';}" onblur="javascript:if(this.value=='') {this.value='Shipment Tracking ...'}" value="Shipment Tracking ..."/>
        
        <input name="button" type="submit" class="SHN" id="button" value="GO"/>
        
    </form>
    script:
    Code:
    function ship(radio) {
        var n1 = document.getElementById('n1');
        var button = document.getElementById(radio);
        n1.value = button.value;
    }
    this will make the text input display the value of the selected radio button.

  3. #3
    Join Date
    Mar 2011
    Posts
    4

    Post

    Quote Originally Posted by moritana View Post
    html:
    HTML Code:
    <form id="Shipment" name="Shipment" method="get" action="tope_results.asp" class="zero" onSubmit="popupform(this, 'join')">
        
        <input type="radio" name="SrchQuery" id="n4" value="CNTR" onclick="ship('n4')" />
        
        <input type="radio" name="SrchQuery" id="n2" value="BLNo" onclick="ship('n2')" />
        
        <input type="radio" name="SrchQuery" id="n3" value="Fln" onclick="ship('n3')"/>
        
        <input name="n1" type="text" class="Textbox" id="n1" size="29" onfocus="javascript:if(this.value=='Shipment Tracking ...') {this.value='';}" onblur="javascript:if(this.value=='') {this.value='Shipment Tracking ...'}" value="Shipment Tracking ..."/>
        
        <input name="button" type="submit" class="SHN" id="button" value="GO"/>
        
    </form>
    script:
    Code:
    function ship(radio) {
        var n1 = document.getElementById('n1');
        var button = document.getElementById(radio);
        n1.value = button.value;
    }
    this will make the text input display the value of the selected radio button.


    Thanks for your code moritana, but its not exactly what I need. I need textbox value which user type in textbox be the value of a radio button which user select from three radio buttons. so for example if user select radio button number 2 then type something in textbox that something could be the value of radio button number 2 which user select, that could happen to other radio buttons as well.


    additional explanation :

    (I have three radio buttons and one text box in a form which is for shipment tracking, now what I need is when I type something in that textbox (which is the value) and select one of those three radio buttons then clicking on go (submit) textbox value and selected radio button value will pass through URL (get method) on the result page I see two different value, one for my textbox and one for the selected radio button ,now I want that selected radio button value be as exact as the textbox one so the selected radio button value should follow the textbox value and both be equal so for example when I type some number like 870 in the textbox and select one of those three radio buttons an submit the form the result page URL have to show the radio button value 870 as the textbox is.)


    Could you guys please give me a hand, thanks so much.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles