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!

enumerate checkbox counting issue

Status
Not open for further replies.

leahyj

MIS
May 5, 2004
107
US
Hello:

For some reason, my code is returning my checkboxes(values) twice. Same result using for loop and do while loop.

Code:
function paynow()
{

var elems = document.lienslist_frm.elements;
var i = 0

do
//for(i=0; i<elems.length; i++)
//trying do while loop this time instead of for loop
{

if(elems[i].type=="checkbox" && elems[i].name=="chkPayNow" && elems[i].checked){ 

	alert(document.lienslist_frm.elements[i].value);
	alert(elems[i].type); 
	alert(elems[i].name); 

	}
i++
}
while(i<elems.length)
return true;
}

This is my form:

Code:
<form name="lienslist_frm">
<td><font size="2">A11348000463</font></td>
<td><font size="2">&nbsp;</font></td>
<td><font size="2">2004</font></td>
<td align="right"><font size="2">$27.59&nbsp;&nbsp;</font></td>
<td align="center"><font size="2">No</font></td>
<td><font size="2"><input type="checkbox" name="chkPayNow" value="A11348000463"></font></td>
</tr>
</table>
</form>

Thanks in advance.
 
this works fine...

Code:
<script type="text/javascript"><!--
function paynow() {
    var elems = document.lienslist_frm.elements;
    for(i=0; i<elems.length; i++) {
        if(elems[i].type=="checkbox" && elems[i].name=="chkPayNow" && elems[i].checked){
            alert(document.lienslist_frm.elements[i].value);
            alert(elems[i].type);
            alert(elems[i].name);
        }
    }
    return true;
}//--></script>

it helps to indent your code, so you can see what different blocks are doing.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
To cLFlaVa:

Thanks.

I am calling my function from a button in another form.

Anyway,

for some reason, I get the values twice.


Thanks.
 
guess what:

I had my function being called from the <form onsubmit="javascript:return paynow();"> tag and the <input onclick="paynow();"> tag.

That's why it was happening twice.

As long as I got your attention, is there any preference or difference?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top