1

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

5

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/

Sign up to request clarification or add additional context in comments.

4 Comments

Popping up the javascript console (shift-ctrl-J in firefox/chrome) would reveal the syntax error.
@MarcB -- and that is how i found it ^_^
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.
Thanks a lot. Also for the tip.
0

You can put an alert('test') in function, to see if function is called.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.