Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

toggle text on multiple buttons

Status
Not open for further replies.

crw150

Technical User
May 27, 2005
20
Please point me in the right direction. The following correctly expands or collapses the notes, but the button value does not toggle between "display" and "hide"--only the first button in the document shows the correct text when clicked. I understand that using the [0] I'm selecting only the first button, but how do I fix that? Do I need a variable? A for loop? An array? Should I be using document.f1.b1.value or getElementById or getElementsByTagName? I keep reading but am too new to JavaScript. I can't tell which way to go. Any help would be greatly appreciated!
Thanks,
crw150

Code:
function togShow(folderID) {
notedivs = document.getElementById('folder'+folderID);
if (notedivs.style.display=="block" || notedivs.style.display==""){
notedivs.style.display="none";
document.f1[0].b1.value="click to display"; 
}else{
notedivs.style.display="block";
document.f1[0].b1.value="click to hide"; 
}}

Code:
<xsl:if test="note">
  <div id="toggleid{generate-id(.)}">
    <form name="f1">					
      <input name="b1" onclick="javascript:togShow('id{generate-id(.)}')" type="button" value="click to hide"/>
    </form>
  </div>						
  <div id="folderid{generate-id(.)}">
    <xsl:apply-templates select="note"/>
  </div><br/><br/>
</xsl:if>
 
Try taking out [0].

[tt] document.f1.b1.value="click to display";
//etc
document.f1.b1.value="click to hide"; [/tt]

Otherwise to be more certain, pass the button object itself to the handler. Like this.

[tt] <input name="b1" onclick="javascript:togShow('id{generate-id(.)}'[blue],this[/blue])" type="button" value="click to hide"/>[/tt]

Then the handler becomes.
[tt]
function togShow(folderID[blue],obj[/blue]) {
notedivs = document.getElementById('folder'+folderID);
if (notedivs.style.display=="block" || notedivs.style.display==""){
notedivs.style.display="none";
[blue]obj[/blue].value="click to display";
}else{
notedivs.style.display="block";
[blue]obj[/blue].value="click to hide";
}}
[/tt]
- tsuji
 
Leaving out [0] did not work, but using "obj" and "this" did. Thank you SO much!!! I worked on this for days and got nowhere.

Now I just have to get another [Display All | Hide All] function to work at the same time.

As a rank beginner, I sincerely appreciate your help!
crw150
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top