Current location: Hot Scripts Forums » General Community » Script Requests » reorder radio buttons


reorder radio buttons

Reply
  #1 (permalink)  
Old 09-21-08, 09:51 PM
tcloud tcloud is offline
New Member
 
Join Date: Sep 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
reorder radio buttons

I need to:
- start with a column of radio buttons
- select one or more radio button(s)
- click an UP or DOWN button (or +/-) and have the button(s) be moved up or down

I found a script that reorders items in an input list but can't figure out how to make it work with radio buttons:
http://members.aol.com/grassblad/html/selReorder2.html

The ideal would be if each radio button could be in a cell in a row of a table and have the entire row or rows, that have been selected, move up or down in the table.

thanks,
Tom
Reply With Quote
  #2 (permalink)  
Old 09-22-08, 01:48 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Radio buttons were designed to select one of many.
This little program will allow you to select one radio button and move it up or down in the list.
And when you submit the form it will display the value of the selected radio button.
Javascript Code:
  1. <html>
  2. <head>
  3. <script>
  4. // Array arr1 holds the name/value pairs of the radio buttons. Add or subtract as many as you need.
  5. var arr1 = new Array(
  6.                      new Array("Radio 1","1"),
  7.                      new Array("Radio 2","2"),
  8.                      new Array("Radio 3","3"),
  9.                      new Array("Radio 4","4"),
  10.                      new Array("Radio 5","5"),
  11.                      new Array("Radio 6","6")
  12.                      );
  13. var v,s;
  14. function shift_down(v)
  15. {
  16.  var l=arr1.length;
  17.  var t="",j=0,i;
  18.  var temp=new Array();
  19.  for(i=0;i<l;i++)
  20.  {
  21.   if(arr1[i][0]==v)
  22.   {
  23.    t=arr1[i];
  24.    }
  25.   else
  26.   {
  27.    temp[j]=arr1[i];j++;
  28.    if(t){temp[j]=t;j++;t="";}
  29.    }
  30.   }
  31.  for(i=0;i<temp.length;i++)
  32.  {
  33.   arr1[i]=temp[i];
  34.   }
  35.  temp="";
  36.  for(i=0;i<arr1.length;i++)
  37.  {
  38.   if(arr1[i][0]==v){s="checked";}else{s="";}
  39.   temp+="<input type='radio' name='radio1' id='"+arr1[i][0]+"' value='"+arr1[i][1]+"' onclick='v=this.id'"+s+"> "+arr1[i][0]+"<br />";
  40.   }
  41.  document.getElementById("div1").innerHTML=temp;
  42.  }
  43. function shift_up(v)
  44. {
  45.  var l=arr1.length;
  46.  var t="",j=l-1,i;
  47.  var temp=new Array();
  48.  for(i=l-1;i>=0;i--)
  49.  {
  50.   if(arr1[i][0]==v&&i>0)
  51.   {
  52.    t=arr1[i];
  53.    }
  54.   else
  55.   {
  56.    temp[j]=arr1[i];j--;
  57.    if(t){temp[j]=t;j--;t="";}
  58.    }
  59.   }
  60.  for(i=0;i<temp.length;i++)
  61.  {
  62.   arr1[i]=temp[i];
  63.   }
  64.  temp="";
  65.  for(i=0;i<arr1.length;i++)
  66.  {
  67.    if(arr1[i][0]==v){s="checked";}else{s="";}
  68.    temp+="<input type='radio' name='radio1' id='"+arr1[i][0]+"' value='"+arr1[i][1]+"' onclick='v=this.id' "+s+"> "+arr1[i][0]+"<br />";
  69.   }
  70.  document.getElementById("div1").innerHTML=temp;
  71.  }
  72. function show_value()
  73. {
  74.  var v = document.getElementsByTagName("input");
  75.  var l = v.length;
  76.  for(i=0;i<l;i++)
  77.  {
  78.   if(v[i].type=="radio")
  79.   {
  80.    if(v[i].checked==true)
  81.    {
  82.     alert(v[i].value);
  83.     }
  84.    }
  85.   }
  86.  }
  87. </script>
  88. </head>
  89. <body onload="shift_down();">
  90. <form action="#" method="post" onsubmit="show_value();return false;">
  91. <div id="div1" style="border:1px solid #000;float:left;padding:10px;"></div>
  92. <p style="clear:both;">
  93. <button onclick="shift_down(v);">Down</button>
  94. <button onclick="shift_up(v);">Up</button>
  95. </p>
  96. <input type="submit" value="Submit" name="submit";>
  97. </form>
  98. </body>
  99. </html>
__________________
Jerry Broughton

Last edited by job0107; 09-22-08 at 02:13 AM.
Reply With Quote
  #3 (permalink)  
Old 09-22-08, 07:27 AM
tcloud tcloud is offline
New Member
 
Join Date: Sep 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
thank you.
Reply With Quote
  #4 (permalink)  
Old 09-22-08, 08:04 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Your welcome.
__________________
Jerry Broughton
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
using java and radio buttons to choose search. PLEASE HELP!!! shelydmb JavaScript 1 03-13-06 03:19 PM
Accessing PHP array in HTML to make radio buttons Newbie2005 PHP 35 10-20-05 01:32 PM
radio buttons hugo84 ASP 1 08-02-05 02:04 AM
Deleting multiple rows using radio buttons and text ciggie PHP 2 03-19-04 07:46 PM
Help with radio buttons and uploading Arctic ASP 3 08-17-03 09:49 AM


All times are GMT -5. The time now is 09:21 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.