Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forcing radio selections 1

Status
Not open for further replies.

Deleted

Technical User
Jul 17, 2003
470
US
Hello all,

Been puling my hair out regarding this. Maybe someone can help me with this. Basically I have a form:

Code:
<form name="this_form">

Item A<br>
<input type="radio" name="pick1" value="1"> 1<br>
<input type="radio" name="pick1" value="2"> 2<br>
<input type="radio" name="pick1" value="3"> 3<br>

Item B<br>
<input type="radio" name="pick2" value="1"> 1<br>
<input type="radio" name="pick2" value="2"> 2<br>
<input type="radio" name="pick2" value="3"> 3<br>

Item C<br>
<input type="radio" name="pick3" value="1"> 1<br>
<input type="radio" name="pick3" value="2"> 2<br>
<input type="radio" name="pick3" value="3"> 3<br>

<input type="submit">
</form>

What I am trying to do is when the user selects a radio (let's say Item A radio 1); the user is only allowed to select either #2 or #3. Basically I want to force the user to select Item 1 = 1, Item 2 = 2, Item 3 = 3 or Item 1 = 2, Item 2 = 1, Items 3 = 3 but no duplicates like Item 1 = 1, Item 2 = 1, Item 3 = 1.

To give you a general idea of what this is. It is basically a rating system from best to worst. So there can't be multiple best's or worst's.

Any help would be great on this.. Thanks in advance.

 

this is a kinda crude solution, but effective. basically, it allows the itemA only at first, then takes that rating and opens up itemB, disabling the itemA choice. then after the itemB rating is selected, it opens up itemC, disabling itemA and itemB rating.

Code:
<script>
function setDisable() {
document.this_form.pick2[0].disabled=true;
document.this_form.pick2[1].disabled=true;
document.this_form.pick2[2].disabled=true;
document.this_form.pick3[0].disabled=true;
document.this_form.pick3[1].disabled=true;
document.this_form.pick3[2].disabled=true;
}
lastSet='';
function removeItem(x,y) {
y=y-1;
 if (x=='pick1') {
 lastSet=y;
 document.this_form.pick1[0].disabled=true;
 document.this_form.pick1[1].disabled=true;
 document.this_form.pick1[2].disabled=true;
 document.this_form.pick2[0].disabled=false;
 document.this_form.pick2[1].disabled=false;
 document.this_form.pick2[2].disabled=false;
 document.this_form.pick3[0].disabled=true;
 document.this_form.pick3[1].disabled=true;
 document.this_form.pick3[2].disabled=true;
 document.this_form.pick2[y].disabled=true;
 document.this_form.pick3[y].disabled=true;
 }
 if (x=='pick2') {
 lastSet=lastSet+','+y;
 lastSetX=lastSet.split(',');
  if ((lastSetX[0]!=0)&&(lastSetX[1]!=0)) {document.this_form.pick3[0].disabled=false;}
  if ((lastSetX[0]!=1)&&(lastSetX[1]!=1)) {document.this_form.pick3[1].disabled=false;}
  if ((lastSetX[0]!=2)&&(lastSetX[1]!=2)) {document.this_form.pick3[2].disabled=false;}
 document.this_form.pick2[0].disabled=true;
 document.this_form.pick2[1].disabled=true;
 document.this_form.pick2[2].disabled=true;
 document.this_form.pick3[y].disabled=true;
 }
}
</script>

<form name="this_form">

Item A<br>
<input type="radio" name="pick1" value="1" onclick=removeItem(name,value);> 1<br>
<input type="radio" name="pick1" value="2" onclick=removeItem(name,value);> 2<br>
<input type="radio" name="pick1" value="3" onclick=removeItem(name,value);> 3<br>

Item B<br>
<input type="radio" name="pick2" value="1" onclick=removeItem(name,value);> 1<br>
<input type="radio" name="pick2" value="2" onclick=removeItem(name,value);> 2<br>
<input type="radio" name="pick2" value="3" onclick=removeItem(name,value);> 3<br>

Item C<br>
<input type="radio" name="pick3" value="1" onclick=removeItem(name,value);> 1<br>
<input type="radio" name="pick3" value="2" onclick=removeItem(name,value);> 2<br>
<input type="radio" name="pick3" value="3" onclick=removeItem(name,value);> 3<br>

<input type="submit">
</form>
<script>setDisable();</script>

does this help your situation?

- g
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top