Jump to content

Does anyone know why this doesn't work in Firefox?


richrock

Recommended Posts

Works fine in other browsers I've tested so far (Chrome & Safari)  ::)

 

<script type='text/javascript'>

// TODO - this does not work if FF - other browsers are fine.
function showPaypal(paypal_value) {

	var src_value = paypal_value;


	var target = 'paypal_details';
	var settingvalue = document.getElementById('showpal_value').value;

	if(src_value == 'on') {
		document.getElementById('paypal_details').style.visibility = 'visible';
	} else {
		document.getElementById('paypal_details').style.visibility = 'hidden';
	}

	alert(document.getElementById('paypal_details').style.visibility);

}
</script>

 

The html bit is this

 

<input type="checkbox" name="showpal" id="showpal_value" onclick="showPaypal(value);" <?php if($agent_show == 'checked') { echo "checked=\"checked\" "; } ?>/>
<?php echo $agent_show . "<br />"; ?>

<div id="paypal_details">
<?php echo $paypal_code; ?>
</div>

 

I can't see anything technically wrong, and it's from a tutorial (modified to suit my needs).  Sorry for all the JS questions, but it's not my strongest point, though I am learning quicky!  :D

Sorry, I was a bit vague  ::)

 

Basically, in Firefox, the element paypal_details will show on a onclick event, but not hide when the element is clicked again.  This works in other browsers, but not FF.  I have firebug installed, but it doesn't show any errors when it fails to hide the div.

 

As for value, I'm sure that can be removed.  It wasn't working before I added that, and still didn't work afterwards,  so I don't think thats the issue.

 

Thanks

As Omirion pointed out, value doesn't appear to be a valid value. The target and settingvalue definitions appear to be redundant code. Plus would it not be better to hide the element with display:none?

 

Personally I'd rewrite your function, seems a little dodgey to me:

 

   function togglePaypal(obj) {
      var ppd = document.getElementById('paypal_details');
      if (ppd.style.display == 'none') {
         ppd.style.display = 'block';
      } else {
         ppd.style.display = 'none';
      }
   }

 

 

Then just call it with:

 

onclick="togglePaypal(this);"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.