Solved

changing button text with javascript

Posted on 2011-03-11
4
493 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
  • 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

770 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