How to change the text of a button

I have a button that when clicked hides / un-hides stuff.

I'd like to change the text of the button based on the state, such as "Click to show pics", then "Click to hide pics"

example here:
Alaska CowboyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Let's suppose this is your button:
<input type="button" value="Button Text" id="myButton1"></input>

You simply use this to change it's text:
document.getElementById("myButton1").value="New Button Text";

This is a test code that does exactly what you are looking for:
<script type="text/javascript"> 
function changeText(){
	if (document.getElementById("myButton1").value=="Click to show pics")	document.getElementById("myButton1").value="Click to hide pics";
		else document.getElementById("myButton1").value="Click to show pics";
<input type="button" value="Click to show pics" id="myButton1" onClick="changeText()"></input>


Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Alaska CowboyAuthor Commented:
Thanks, check it out now . . .
Dave BaldwinFixer of ProblemsCommented:
Give the submit button an 'id' and change the value when you hide and unhide the pics.

<input id="pictoggle" type="submit" value="Click for pics" class="btn" onmouseover="this.className='btn btnhov'" onmouseout="this.className='btn'"/>

document.getElementById("pictoggle").value = "click to Hide Pics";

Open in new window

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Alaska CowboyAuthor Commented:
Dave, thanks too, checking it out now.
Alaska CowboyAuthor Commented:
Glad to hear that.

Dave BaldwinFixer of ProblemsCommented:
Good job, I like the way you did that.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.