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

why does it bugs ? (form problem)

Status
Not open for further replies.

tyris

Programmer
Nov 2, 2000
311
FR
i have this code, that gives me the value selected in 2 radio groups (company and people). this code works very well when the 2 radio groups are selected :

========================

var RadioComp_sel="none";
var RadioPep_sel="none";

function GetCurCompSel() {
for (i=0; i<= document.myForm.Company.length; i++) {
if (document.myForm.Company.checked) {
RadioComp_sel = document.myForm.Company.value;
break;
}
}

}

function GetCurPepSel() {
for (i=0; i<= document.myForm.people.length; i++) {
if (document.myForm.people.checked) {
RadioPep_sel = document.myForm.people.value;
break;
}
}

}

GetCurCompSel();
GetCurPepSel();
alert(RadioComp_sel);
alert(RadioPep_sel);

========================

the problem is that when there is at least one of this radio group where nothing is selected, IE tels me that document.myForm.object.checked is not an object.

I know it doesn't exists, thats why there is an IF test in front of this lign. But IE acts as if the &quot;IF&quot; was not there.

What's the bug with my test ?
what can i do if y want to keep the string &quot;none&quot; if one radio group is not selected ?

sorry again for my bad english
- Best regards,
Elise
 
can you repost your code, but uncheck &quot;process TGML&quot; at the bottom right of the entry form thing. It screws up peoples code some times. jared@aauser.com
 
try using the &quot;elements&quot; array instead of naming the radio group - this works fine, and won't bug
(instead of
for (i=0; i<= document.myForm.Company.length; i++) {
if (document.myForm.Company.checked) {
RadioComp_sel = document.myForm.Company.value;
break;
}
}

use

for (index=0; index<= document.myForm.elements.length; i++) {
if (document.myForm.elements[index].checked &amp;&amp; document.myForm.elements[index].name=='Company') {
RadioComp_sel = document.myForm.Company.value;
break;
}
}

 
An alternate method would be to set the value of the variable when the radio button is checked. Then you can do without the GetCurCompSel() and GetCurPepSel() functions.

for example, instead of
<input type=radio name=Company value=ABC>
you could use
<input type=radio name=Company onclick=RadioComp_sel='ABC'>



nick bulka

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top