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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Special radio button validation 2

Status
Not open for further replies.

dodge20

MIS
Joined
Jan 15, 2003
Messages
1,048
Location
US
I have a form that takes the value of a checked radio button and passes that to another button. Then that new button passes its checked value to another new button.

My problem is, once the third button is checked, you can go back and change the first button, but the third button value still remains the same. For example:

radgroup1 value x checked
radgroup2 value x checked
radgroup3 value x checked

Then you decide to change radgroup1 to y so you have
radgroup1 value y checked
radgroup2 value x checked
radgroup3 value x checked

When this can't be because you are passing the values from radiogroup to radiogroup. So, ideally, when you change x to y, it would then in turn change all the x's to y's. Here is a section of my code. If it helps, this is a basketball bracket for those of you who know what that is.

Code:
<script>
function dothis(obj1,obj2,obj3)
{
var frm = document.frm
for(i =0; i <frm[obj1].length; i++)
{
if(frm[obj1][i].checked)
var temp = frm[obj1][i].value
}
for(i =0; i <frm[obj2].length; i++)
{
if(frm[obj2][i].checked)
var temp2 = frm[obj2][i].value
}
document.frm[obj3][0].value = temp;
document.frm[obj3][1].value = temp2;
document.getElementById(obj3+'_0').innerHTML = temp;
document.getElementById(obj3+'_1').innerHTML = temp2;
}
function dothis2(obj)
{
var frm = document.frm
for(i =0; i <frm[obj].length; i++)
{
if(frm[obj][i].checked)
var temp = frm[obj][i].value
}
document.getElementById('me').innerHTML = "THE WINNER IS \n"+temp
}
</script>

<input type="radio" name="r1g8" value="Gonzaga"
		  onclick = "dothis('r1g7','r1g8','r2g4');">
          <FONT FACE="Arial Narrow, Arial" SIZE="2"><font face="Times New Roman, Times, serif">Gonzaga</font></FONT></label>
          <br>
          <label>
          <input type="radio" name="r1g8" value="Valparasio"
		  onclick = "dothis('r1g7','r1g8','r2g4');">
        <FONT FACE="Times New Roman, Times, serif" SIZE="2">Valparasio

<input type="radio" name="r2g4"onclick = "dothis('r2g3','r2g4','r3g2');">
          <span id = "r2g4_0"></span>
  </label>
          <br>
          <label>
          <input type="radio" name="r2g4" onclick = "dothis('r2g3','r2g4','r3g2');">
          <span id = "r2g4_1"></span>
  </label>
      <input type="radio" name="r3g2" onclick = "dothis('r3g3','r3g4','r4g1');">		  
          <span id = "r3g2_0"></span>
  </label>
          <br>
          <label>
          <input type="radio" name="r3g2" onclick = "dothis('r3g3','r3g4','r4g1');">		  
          <span id = "r3g2_1"></span>
  </label>



Dodge20
 
Can you provide an online (working) example of this?
 

I notice that you are setting the value for the radio buttons, rather than the checked property. Maybe this is the problem?

Incidentally, you really should remove all references to the FONT tag, and use CSS - it is no longer part of the HTML spec, AFAIK.

Hope this helps,
Dan

 
Well, I am inserting this into a database, so I thought I had to set the value. Is there a better way to do this?

Dodge20
 
Also is there a way to have the undefined value show up in red or even just blank? I have a validation, but I think it would be easier if you could see something missing or sticking out.

Dodge20
 
Anybody have any ideas??

Dodge20
 

Personally, I would re-architect the solution, using JS a lot more. While some people may argue against this (accessibility, etc), your code is already using JS quite heavily, so you wont be alienating any more people.

Use of DOM methods to create the tables would mean your code could shrink down so much.

Hope this helps,
Dan

 
At the moment, the values will not filter down because the function only says to alter the value in the next box, and the values only change on an onclick event. Perhaps you could add onchange events?

However, I agree with Dan, you should re-architect the solution. Store your teams in some kind of datastructure (database, XML or in Javascript array), then create the structure of the bracket dynamically using DOM methods. Once you've done this, you should find it much easier to write functions to filter down results.

Jon
 
Ok, can you help me do this? I don't know what DOM methods are. I don't have any javascript training as you can probably tell. I was just happy to make it work.

Dodge20
 
OK. You wanna redo the whole thing?
 
If it is best, then yes. And also if you are willing to help me out. I know this probably isn't a quick fix.

Dodge20
 
Sure, I'll help.

I'd advise against using a table, I'd use divs and style sheets to make code smaller and more maintainable. I'd create an javascript array or XML file with the team names and dynamically create the divs with DOM methods.

Do you want something like this (only editable):

 
Yes, something like that would be great! I will want to pull the information from a database. I am not sure what the numbers are behind the teams, but I am sure you do.

So I won't use radio buttons then? Will I just be able to click on the team name, and that will advance that team?

Dodge20
 
I presume the numbers are the scores.

You saying you want to pull the team names from a database? Or submit the data to a database? Or both?

You can use radio buttons if you want or a select box or just have the user click on the team name, whatever you want really.
 
Both, I will probably pull the names from a table, and submit the user picks to another table, but it isn't necessary to pull the team names from a database. I think clicking on the team name is probably better than using radio buttons, but I don't know how to do that.

Dodge20
 
You always gonna have the same number (64) teams?

Whats the significance of having two halves to the bracket(one on left and one on right)? It would probably be easier to have it all on one side.
 
Yes, I will always have 64 teams.

If it is easier to do all 1 side, then we can do it that way, there really isn't a huge significance. It is just how people are used to doing it. I can make a print version where they view the bracket in the traditional way, but the submission of the bracket can be done in whatever way is easiest.

Dodge20
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top