iUI Toggle button

100 views
Skip to first unread message

anmldr

unread,
Jan 18, 2009, 11:57:34 PM1/18/09
to iPhoneWebDev
I am using the toggle button from iUI. I need to add to a way to find
out if the value is "Yes" vs "No" or "True" vs "False". In my case, I
am using "Pounds" vs "Kilograms" (or lbs vs kgs) before I perform a
calculation. I do NOT know js and so would appreciate some help. What
would I add in the HTML and/or js to be able to see which is selected?

The js for this is:

(function() {
addEventListener("click", function(event)
{
var div = findParent(event.target, "div");
if (div && hasClass(div, "toggle"))
{
div.setAttribute("toggled", div.getAttribute("toggled") !=
"true");
event.preventDefault();
}
}, true);

function findParent(node, localName)
{
while (node && (node.nodeType != 1 || node.localName.toLowerCase
() != localName))
node = node.parentNode;
return node;
}

function hasClass(self, name)
{
var re = new RegExp("(^|\\s)"+name+"($|\\s)");
return re.exec(self.getAttribute("class")) != null;
}
})();

Linda

davidroe

unread,
Jan 19, 2009, 12:33:28 AM1/19/09
to iPhoneWebDev
which <div /> currently has class="toggle", add id="PvsK"

then you can call document.getElementById("PvsK").getAttribute
("toggled")

HTH,
/dave
Reply all
Reply to author
Forward
0 new messages