TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Javascript, AJAX, E4X (http://www.talkphp.com/javascript-ajax-e4x/)
-   -   Update Text if div is showing or hiding (http://www.talkphp.com/javascript-ajax-e4x/4832-update-text-if-div-showing-hiding.html)

russellharrower 08-09-2009 03:00 PM

Update Text if div is showing or hiding
 
Hi i found this code however it is not updating the text correctly on my computer.

javascript Code:
<script type="text/javascript">

function ShowHide(elementId)
{
    var element = document.getElementById(elementId);
    if(element.style.display != "block")
    {
        element.style.display = "block";
    }
    else
    {
        element.style.display = "none";
    }
}
function UpdateText(element)
{
    if(element.innerHTML.indexOf("Show") = -1)
    {
        element.innerHTML = "show<img src='images/YOUR THEME /fastreply.gif'>";
    }
    else
    {
        element.innerHTML = "hide<img src='images/YOUR THEME/fastreply.gif'>";
    }
}
</script>
php Code:
<?php
print '<a href="javascript:void(0);" onclick="ShowHide(\'search'.$row['id'].'\');UpdateText(this);">';
?>

If anyone can help that would be alsome, I thought it was the UpdateText because I have more then one of these on the same page since it prints it 10 times.

But after 5 hours working at it, can't get it to work...

please help if you can

codefreek 08-09-2009 03:40 PM

Please change, to highlight=javascript
and read, http://www.talkphp.com/lounge/4563-p...e-talkphp.html

Thankyou
-cf

adamdecaf 08-09-2009 07:09 PM

  1. Why are you assigning a value in the 2nd if statement?
  2. Why are you not just checking if the image is displayed and if so set it's .style to hidden. (Then vise-versa)
  3. It would help if we had more context (what exactly you're trying).
  4. http://jslint.com


All times are GMT. The time now is 10:06 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0