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

Differentiating check boxes and radio buttons

Status
Not open for further replies.

DKL01

Programmer
Sep 14, 2000
233
US
Hi,

I have ASP file with checkboxes and a Save button. When I click on save button I am checking whether one of the checkboxes is selected using

var objInput = document.all.tags("input");
for(ix=0;ix<objInput.length;ix++) {
if (objInput(ix).checked) {
bCheckFound = true;
intCount++;

Now I added 2 option buttons( radio buttons ) to the same screen. Is there any way ( other than having them in two different forms ) I can change the above code so that it checks only check boxes .

Thanks
 
They should be named differnetly.. Radio buttons are mutually exclusive, so you should have a form element name for the radio buttons and one for the check boxes.. Check for the check boxes by their name.. I'm not a java scripter, so your code doesn't help me much, but you should have something like

<input type =checkbox name = chkMyCheck>

The only thing you check is the name of the check box.. That's how it would be done server side anyway..
 
Hi.

You have to named the check boxes like radios. The
document.all[&quot;YOURELEM&quot;] will give back a collection of your elements. See the following script:

<html>
<Script Language=&quot;JavaScript&quot;>
function ff()
{
var elements=document.all[&quot;myElem&quot;];
var num=document.all[&quot;myElem&quot;].length;
for(i=0;i<num;i++){
alert(elements[ i ].value);
}
}
</Script>
<body>
<input type=text name=&quot;myElem&quot;>
<input type=text name=&quot;myElem&quot;>
<input type=text name=&quot;myElem&quot;>
<input type=text name=&quot;myElem&quot;>

<input type=&quot;button&quot; value=&quot;kkk&quot; onclick=&quot;ff()&quot;>
</body>
</html>

regards, Kirilla
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top