/    Sign up×
Community /Pin to ProfileBookmark

Radio Button Onchange Help

Has anyone seen a script that will onchange a radio button from one to another and add a second value field?

Here is my example:
If I select radio sortby 1 I just get sortby=distance.
If I select radio sortby 2 I get both sortby=registration AND 3. reverse=yes

See example:
1. <input type=”radio” name=”sortby” value=”distance”> Sort By Zip Code Radius

Or

  • 2. <input type=”radio” name=”sortby” value=”sortable_register_date”> Sort By Registration Date

  • 3. <input type=”hidden” name=”reverse” value=”yes”>
  • to post a comment
    JavaScript

    9 Comments(s)

    Copy linkTweet thisAlerts:
    @KorAug 17.2006 — why do you need the hidden input? can't you manage the data on the server level?
    Copy linkTweet thisAlerts:
    @HDCauthorAug 17.2006 — Unfortunately not, by default the perl script has the results in random order. So choosing sortable_register_date will list them from oldest to newest and then adding reverse=yes results them how I want, from newest members on top.

    Hard coding any of this would result in my zip code distance not functioning properly from the closest distance on top in my results when it is chosen.

    Hope this makes since.
    Copy linkTweet thisAlerts:
    @HDCauthorAug 18.2006 — Does anyone else have an idea for this. Below is what I started to work on but got hung up and thought I would ask before spending alot of time.



    <HEAD>

    <script language="JavaScript">

    <!--


    function showDiv( id ) {

    document.all.distance.style.visibility = 'hidden';

    document.all.sortable_register_date.style.visibility = 'hidden';

    document.all.distance.value = '';

    document.all.sortable_register_date.value = '';

    document.all[ id ].style.visibility = 'visible';

    document.all[ id ].focus();

    }

    -->

    </script>

    </HEAD>


    <BODY>

    Sort Distance:

    <input type=radio name=distance size=30 value="distance" style="visibility:hidden">

    <br><strong>OR</strong><br>


    Sort Date:

    <input type=radio name="sortable_register_date" onClick="showDiv( 'sortable_register_date' );">

    <input type=hidden name="reverse" size=20 value="yes" style="visibility:hidden">
    Copy linkTweet thisAlerts:
    @KorAug 18.2006 — just a note, so far... document.all is a deprecated only IE method to refere an element. use modern DOM methods (by id, by name, by tagname) or, at least (but it works only for the form's elements), the classical reference

    [COLOR=Blue]document.forms['formname'].elements['elname'][/COLOR]

    or even in the short JSON

    [COLOR=Blue]document['formname']['elname'][/COLOR]

    or even

    or, if no need for a dynamic handle

    [COLOR=Blue]document.formname.elname[/COLOR]

    One more note: If an input is type="hidden" does not mean only that he is not [I]visual[/I] invisible. He simply has a [B]type[/B], not a [B]visibility[/B]. It is used to collect and submit some data which are not to be shown in the address bar as querry. Despite the resemblance, type="hidden" is completely other thing than CSS visibility="hidden"
    Copy linkTweet thisAlerts:
    @HDCauthorAug 18.2006 — Thanks Kor for the help. Going this route do you think it is possible to do what I want?
    Copy linkTweet thisAlerts:
    @KorAug 18.2006 — I confess I have not really understood your first aim. Can you detail a little bit. It looks like an easy task, if clear enough. Now: you want a text field to be visible when one of the radio buttons is checked and "visual hidden" (and will not submit it's data) when the other one is checked?
    Copy linkTweet thisAlerts:
    @HDCauthorAug 18.2006 — Actually it is very simple.

    I want 2 different radio buttons. If the second button is chosen then I want another radio button chosen as well, or preferably hidden for the "reverse=yes" since visitors don't need to see this.
    Copy linkTweet thisAlerts:
    @muazzezAug 19.2006 — code:

    [color=olive]

    <html>

    <SCRIPT>

    function HDC() {

    var a = document.getElementById('r0');

    var b = document.getElementById('r1');



    if (a.checked==true) { b.checked=true ; }



    }

    </SCRIPT>

    <body>

    <form>



    <input type="radio" id="r0" name="r0" onclick="HDC();"> evet



    <input type="radio" id="r1" name="r1" onclick="HDC();"> hay&#305;r





    </form>

    </body>

    </html>[/color]


    [color=tomato]

    <html>

    <SCRIPT>

    function HDC() {

    var a = document.getElementById('r0');

    var b = document.getElementById('r1');



    if (a.checked==true) {

    b.checked=true;

    b.style.display="block" }



    }

    </SCRIPT>

    <body>

    <form>



    <input type="radio" id="r0" name="r0" onclick="HDC();">evet



    <input type="radio" id="r1" name="r1" onclick="HDC();" style="display:none;">hay&#305;r





    </form>

    </body>

    </html>[/color]


    [color=blue]

    <html>

    <SCRIPT>

    function HDC() {

    var a = document.getElementById('r0');

    var b = document.getElementById('r1');

    var c = document.getElementById('div');



    if (a.checked==true) {



    c.style.display="block" }



    }

    </SCRIPT>

    <body>

    <form>



    <input type="radio" id="r0" name="r0" onclick="HDC();"> evet

    <div style="display:none;" id ="div">


    <input type="radio" id="r1" name="r1" onclick="HDC();" > hay&#305;r

    </div>





    </form>

    </body>

    </html>[/color]


    [color=lightseagreen]

    <html>

    <SCRIPT>

    function HDC() {

    var a = document.getElementById('r0');

    var b = document.getElementById('r1');

    var c = document.getElementById('div');



    if (a.checked==true) {

    b.checked=true;

    c.style.display="block" }



    }

    </SCRIPT>

    <body>

    <form>



    <input type="radio" id="r0" name="r0" onclick="HDC();"> evet

    <div style="display:none;" id ="div">


    <input type="radio" id="r1" name="r1" onclick="HDC();" > hay&#305;r

    </div>





    </form>

    </body>

    </html> [/color]
    Copy linkTweet thisAlerts:
    @KorAug 21.2006 — Yet I don't understand why you need that. If a radio button is checked and itls value, nomatter which, is submitted to the server, to an application, you may simply instruct [I]that[/I] application to set [I]that[/I] value YES to be used further.
    ×

    Success!

    Help @HDC spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.2,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,
    )...