I'm having a simple issue with calling a javascript function. I've been playing with this for hours and I can't see the problem. Hopefully another perspective can help.
in the of my php file:
<script type="text/javascript">
function showShareDiv(objid){
var div = document.getElementById('share'+objid);
if (div.style.display=='none'){
div.style.display='block';
}
else{
div.style.display='none');
}
}
</script>
This is just to show/hide a div with name "share"+number (eg. share104). When I look at the source the $obj->id correctly names the div and function onclick name.
Here is the button:
<div id="sharebutton" style="width:100%;" onclick="showShareDiv('<?=$obj->id?>');">
<center>Share</center>
</div>
<div id="share<?=$obj->id?>" style="display:none;">
SHARE BUTTONS GO HERE
</div>
Any help is appreciated.
2 Answers 2
You have an extra )
function showShareDiv(objid){
var div = document.getElementById('share'+objid);
if (div.style.display=='none'){
div.style.display='block';
}
else{
div.style.display='none'; //had a `)` here
}
}
Now it works: http://jsfiddle.net/maniator/eHMZR/
answered Jun 23, 2011 at 20:12
Naftali
147k41 gold badges247 silver badges304 bronze badges
Sign up to request clarification or add additional context in comments.
4 Comments
Marc B
Popping up the javascript console (shift-ctrl-J in firefox/chrome) would reveal the syntax error.
Naftali
@MarcB -- and that is how i found it ^_^
Marc B
Yep. Seems to be a common trend here for people to fly blind and blindfolded, never bothering to try the logging systems available to them.
SunnyD
Thanks a lot. Also for the tip.
You can put an alert('test') in function, to see if function is called.
answered Jun 23, 2011 at 20:21
Adrian B
1,6601 gold badge20 silver badges31 bronze badges
Comments
default