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!

passing form element name through a function

Status
Not open for further replies.

MJB3K

Programmer
Jul 16, 2004
524
GB
Hi, i have a problem passing a form element name through a function to act upon it. I dont know why it is not working.

The problem is that the function isn't picking up the form element that is being passed through.

The PHP outputs the correct name
Code:
<input type="checkbox" name="group1_<?php echo $name; ?>" value="<?php echo $pts; ?>" onclick="javascript:addPoints('group1_<?php echo $name; ?>', 'group1total',this.value);" />
Code:
function addPoints([COLOR=red]cb[/color], gr, pts){
	
	var curPts = parseInt(document.getElementById(gr).innerHTML);
	
	var cbname = document.memlist.cb;

	alert(cbname);
	
	

	// see if checkbox is checked or not for addition / subtraction
	
	if(document.memlist.[COLOR=red]cb[/color].checked == true){
			alert("yh");
			var newTot = curPts +  parseInt(pts);
	}else{
			alert("na");
			var newTot = curPts -  parseInt(pts);
	}
	
document.getElementById("group1total").innerHTML = newTot;
}
any ideas on how to make it work?

Regards,

Martin

Computing Design And Services:
 
Why not show us what is actually being output by the PHP? Right now we have no idea.

That aside, you'd probably need to change this:

Code:
document.memlist.cb.checked

to this:

Code:
document.memlist[cb].checked

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top