Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

When button clicked twice do something

javascript

  • Please log in to reply
1 reply to this topic

#1 bluefenix

bluefenix

    CC Newcomer

  • Member
  • PipPip
  • 11 posts
  • Programming Language:Java, PHP, PL/SQL
  • Learning:C#, JavaScript, Visual Basic .NET

Posted 06 November 2012 - 02:54 PM

I need that when a button is clicked once it will show the message "Hide. And when clicked twice returns to the original message "Show". The first thing I already did it, I only need help with the second thing, that being the second click.

function show()
	{
		document.myform.button.value ="Hide";//Changes message on button when clicked.
		document.myform.button.innerHTML= "Hide";
	}
	
	<form>
	<input type=button value= "Show" name="button" id= "idButton"
	onclick="show()">
	</form>

Edited by BenW, 07 November 2012 - 04:46 AM.
Added code tags

  • 0

#2 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 07 November 2012 - 01:04 AM

something like this :

function show()
	{
	var state = "Hide";
   if( document.myform.button.value == "Hide" ) { state = "Show"; }

	document.myform.button.value =state;
	document.myform.button.innerHTML=state;
	}

that could suit you.

Edited by BenW, 07 November 2012 - 04:46 AM.
Fixed code tags typo

  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download