View Full Version : boolean value for a button?

12-07-2010, 09:31 PM

I'm trying to modify this function:

function togglePoly(poly_num) {
if (document.getElementById(poly_num)) {
if (document.getElementById(poly_num).checked) {
} else {

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, 09: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?


SHOW your code for the actual button.

12-07-2010, 10: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, 10:08 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">


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' ]();

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


Old Pedant
12-07-2010, 10: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, 10: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();