On Mar 5, 7:53 am, "windandwaves" <nfranc...@gmail.comwrote:
Quote:
Hi Folk
>
I want to add an "onClick" function to the radio boxes, but I am
having trouble. Can you help me
>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
There have been many long discussions on whether pages should use
XHTML or HTML, none have shown any significant benefit to using XHTML
on the web. The disadvantages are great, just use HTML unless you
have a really good reason to use XHTML.
Quote:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>leetMachines</title>
<style>
body {width: 600px; margin-left: auto; margin-right: auto;}
label {display: block;}
h2 {color: green;}
p.moreinfo {float: right;}
d.options {clear: right;}
h2, p, div {margin: 0px; padding: 0px;}
</style>
<script type="text/javascript">
function starter(elname) {
obj = document.getElementById(elname);
Better to keep variables local with 'var':
var obj = document.getElementById(elname);
Quote:
addclicks(obj);
>
}
>
function addclicks() {//gets all variables from a form
You pass a reference to obj when you call the function, but don't
assign it to a local variable - you depend on its being a global
variable. Much better to give it a local variable:
function addclicks(obj) {
Quote:
for (i=0; i < obj.childNodes.length; i++) {
Counters should never be allowed to become global:
for (var i=0, len=obj.childNodes.length; i<len; i++) {
Quote:
var newobj = obj.childNodes[i];
tgname = newobj.tagName
var tgname = newobj.tagName
Quote:
if(tgname) {
if (tgname == "INPUT" || tgname == "input") {
Usually:
if (tgname.toLowerCase() == 'input') {
Quote:
newObj.onClick = gonow;
}
}
addclicks(newobj);
This will recursively call addclicks. An input can't have any
children, so it's pointless.
If you only want to add onclick's to inputs, why not use
getElementsByTagName?
function addclicks(obj){
var nodes = obj.getElementsByTagName('input');
var i = nodes.length;
while (i--){
nodes[i].onclick = gonow;
}
}
--
Rob