?
Solved

changing button text with javascript

Posted on 2011-03-11
4
Medium Priority
?
507 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
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…
Suggested Courses

801 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