CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Ajax and Design (http://www.codingforums.com/forumdisplay.php?f=55)
-   -   toggle() more or less [text] (http://www.codingforums.com/showthread.php?t=132342)

blast 01-31-2008 03:40 PM

toggle() more or less [text]
 
Hello All,

I am trying to find some help on using prototype/scriptaculous toggle()

Code:

<div>
Initial Text of the paragraph
<div style="display: none;" id="jan1">
    whatever more text i want to show.
</div>

<a href="javascript:void(0);" onClick="showHide('do_more_less','jan1'); return false;"><span id="do_more_less">More</span></a>

</div>

here is the JS

Code:

function showHide(id, iShow)
{
        var id = id;
        var iShow = iShow;
        var moreLess = document.getElementById(id).innerHTML;
        moreLess = (moreLess == "More") ? "More" : "Less";
        Element.toggle(iShow);
}


now what im trying to do is....have the opening text (which if there is an easier way, please let me know)...when you click on 'more' it will toggle the ID to display it (simple enough), BUT....i want the word 'more' to change to 'less'

any help would be appreciated.

A1ien51 02-01-2008 05:19 AM

If you write this line
Code:

moreLess = (moreLess == "More") ? "More" : "Less";
to be if statements it would look like:
var moreLess;
Code:

if(moreLess == "More"){
  moreLess = "More";
}
else{
  moreLess = "Less";
}

Do you see the problem?
Eric


All times are GMT +1. The time now is 10:33 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.