SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    germany
    Posts
    263
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Radio Button Issue

    Hai
    i have 5 radio buttons.Assume a user click a radio button.
    by default radio 1 is checked
    now assume user click 2 i check certain conditions and based on that javascript function i return true or false, and if i return false then that radio button is not checked, and in that case i want to make the previous radio button checked.

    So basically like this
    i click a radio button and if my function return false then, i should make the previous one which was checked true.how to do using javascript
    with regards
    vimal
    Knowledge is all about Sharing

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if i return false then that radio button is not checked, and in that case i want to make the previous radio button checked.
    That's what returning false does: it prevents the the current radio button from being checked, which means the previous button stays checked.

    Code:
    function onclick_func()
    {
    	...
    	...
    	
    	if(result==true) return true;
    	else return false;
    	
    }

  3. #3
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    germany
    Posts
    263
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the function which came in my email is different from what it was here

    var previous=document.my_form.radio_group1[0];

    function onclick_func(radio_button)
    {
    ...
    ...

    if(result==true)
    {
    previous=radio_button;
    return true;
    }
    else
    {
    previous.checked = true;
    return false;
    }
    }

    So you want to store the previous value in a variable.
    I have like 5 set of radio buttons ie radio1[0] --radio[4] and anything may be checked before checking any of the above four.so how to keep track of what was checked before?

    with regards
    vimal
    Knowledge is all about Sharing

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd"
    >

    <
    html>

    <
    head>
      <
    title></title>
    <
    script language="JavaScript" type="text/javascript">
    <!--
    var 
    RadioAry=new Array();

    function 
    SetRadio(){
     if (
    RadioAry.length>0){
    //  do your conditionals here
      
    alert('Previous\n'+RadioAry)
     }
     for (
    i=0;i<document.tom.fred.length;i++){
      
    RadioAry[i]=document.tom.fred[i].checked;
     }
     
    alert('Current\n'+RadioAry)
    }
    //-->
    </script>
    </head>

    <body>
    <script> vic=0; </script>
    <form name="tom" >
    <input type="radio" name="fred" checked="checked" onclick="javascript:SetRadio();" >
    <input type="radio" name="fred" onclick="javascript:SetRadio();" >
    <input type="radio" name="fred" onclick="javascript:SetRadio();" >
    <input type="radio" name="fred" onclick="javascript:SetRadio();" >
    <input type="radio" name="fred" onclick="javascript:SetRadio();" >
    </form>

    </body>

    </html> 

  5. #5
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    germany
    Posts
    263
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello Vw Philips,
    I couldnt able to tweak this function to what i wanted to,
    Could you help me out to fix that one?

    with regards
    vimal
    Knowledge is all about Sharing


Bookmarks

Posting Permissions

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