• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 559
  • Last Modified:

changing button text with javascript

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
scm0sml
Asked:
scm0sml
  • 2
1 Solution
 
chaitu chaituCommented:
you want to change the button value then
document.getElementById(button).value= '-';
0
 
chaitu chaituCommented:
check this also
document.getElementById(button).innerHTML= '-';
0
 
ovi_mihaiCommented:
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
 
A_NilssonCommented:
Hi,

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

Good luck!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now