Solved

changing button text with javascript

Posted on 2011-03-11
4
498 Views
Last Modified: 2012-05-11
Hi,

I have the javascript function below. The line:
document.getElementById(button).innertext = '-';                
isn't working.

What am I doing wrong?

function showhiderow(id,button) {	

	if (document.getElementById) { 
	    
		if (document.getElementById(id).style.display == 'none')
		{
		    document.getElementById(id).style.display = 'block';
		    document.getElementById(button).innertext = '-';		    
		}
		else
		{				
		    document.getElementById(id).style.display = 'none';
		}
	}	
}

Open in new window

0
Comment
Question by:scm0sml
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
chaitu chaitu earned 500 total points
ID: 35106494
you want to change the button value then
document.getElementById(button).value= '-';
0
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 35106499
check this also
document.getElementById(button).innerHTML= '-';
0
 
LVL 3

Expert Comment

by:ovi_mihai
ID: 35106519
It depends where the button label is written.

<button type="button" id="myButton2">Button Label</button>  
    - .innerHTML or better    .childNodes[0].nodeValue

or

<input type="button" value="Button Text" id="myButton1"></input>
   - .value

http://www.permadi.com/tutorial/jsInnerHTMLDOM/index.html
0
 
LVL 1

Expert Comment

by:A_Nilsson
ID: 35106602
Hi,

I believe that you should use document.getElementById(button).value instead ov document.getElementById(button).innertext .

Good luck!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question