...

View Full Version : boolean value for a button?



xelawho
12-07-2010, 08:31 PM
hi,

I'm trying to modify this function:


function togglePoly(poly_num) {
if (document.getElementById(poly_num)) {
if (document.getElementById(poly_num).checked) {
gpolys[poly_num].show();
} else {
gpolys[poly_num].hide();
}
}
}

which works for a checkbox to one that works for a button.

I guess I'm stuck on what to replace "checked" with there in the 3rd line.

is there some one word answer, or do I need to I rewrite the function to be more button-friendly?

thanks in advance

Old Pedant
12-07-2010, 08:52 PM
??? So how will you inform the USER what the state of the button is? Change the value in the button? Use an image and change the image?

WORK WITH US!!!

SHOW your code for the actual button.

xelawho
12-07-2010, 09:00 PM
sorry, didn't realise that was necessary. the button fires the function:


sidebar_html += '<input type="button" onclick="togglePoly('+poly_num+')" value="Go!"<br />';

so I guess the user will know the state because the function will have fired (?)

Logic Ali
12-07-2010, 09:08 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>TEST</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>
<script type="text/javascript">

gpolys=[];

gpolys['nuts'] =
{
show:function(){ alert('Show'); },

hide:function(){ alert('Hide'); }
}

function togglePoly( poly_num )
{
var btn = document.getElementById(poly_num);

gpolys[poly_num][ ( btn.checked ^= true ) ? 'show' : 'hide' ]();
}
</script>

<input type=button id='nuts' value = 'Go' onclick='togglePoly( this.id )'>

</body>
</html>

Old Pedant
12-07-2010, 09:23 PM
REWRITE OF THIS MESSAGE: Are you suggesting that he simply add a "checked" attribute to his buttons?

Okay, I guess that works.

Old Pedant
12-07-2010, 09:28 PM
This is a bit of a stab in the dark, but here goes:


function togglePoly(poly_num) {
var seg = gpolys[poly_num];
if ( seg.style.visibility == "visible" ) seg.hide(); else seg.show();
}

If the hide/show code is using style.display, instead, then try


function togglePoly(poly_num) {
var seg = gpolys[poly_num];
if ( seg.style.display != "none" ) seg.hide(); else seg.show();
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum