2 Replies - 532 Views - Last Post: 21 September 2012 - 02:29 AM

#1 theHealer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-September 12

A button that, when clicked shows another button in its place.

Posted 20 September 2012 - 05:32 PM

Using html, css, php, or javascript.

I'm having a little trouble trying to create a button that when clicked, shows another button in its place. Then when this second button is clicked, the first one is displayed again.

I

<form method="process.php" action="get">
<button type="submit" name="bid" id="bidbutton">Place Bid</button>
					<button type="submit" name="unbid" id="unbidbutton">Remove Bid</button>
				</form>


<?php
					/* what the bid/unbid buttons do - NEED TO FIX */
					if(isset($_POST['bid'])) {
						echo "You have a placed a bid on this item";
						if(isset($_POST['unbid'])) {
							echo "You have removed your bid on this item";
						} else {
							echo "You must place a bid before you can remove it";
						}
					}

This post has been edited by Dormilich: 21 September 2012 - 02:19 AM
Reason for edit:: please use [code] [/code] tags when posting code


Is This A Good Question/Topic? 0
  • +

Replies To: A button that, when clicked shows another button in its place.

#2 theHealer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-September 12

Re: A button that, when clicked shows another button in its place.

Posted 20 September 2012 - 05:38 PM

Using html, css, php, or javascript.

I'm having a little trouble trying to create a button that when clicked, shows another button in its place. Then when this second button is clicked, the first one is displayed again.

I tried it like this, but it doesn't seem to work at all.

<form method="process.php" action="get">
   <button type="submit" name="btnOne" id="fbutton">First button</button>
   <button type="submit" name="btnTwo" id="sbutton">Second button</button>
</form>


<?php
   if(isset($_POST['fbutton'])) {
      echo "You have clicked the first button";
      if(isset($_POST['sbutton'])) {
	 echo "You have clicked the second button";
      }
   }
?>

This post has been edited by Dormilich: 21 September 2012 - 02:19 AM
Reason for edit:: please use [code] [/code] tags when posting code

Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3402
  • View blog
  • Posts: 9,617
  • Joined: 08-June 10

Re: A button that, when clicked shows another button in its place.

Posted 21 September 2012 - 02:29 AM

it doesn’t work like you assume it to since HTTP (the language the browser (HTML) and the server (PHP) talk to each other) is unaware of any previous action (so-called: stateless).
when you click a button only that button’s name and value is sent over. to memorise the previous button clicked you would need to make PHP explicitly remember the last action, for instance through a session (where you can save data of your choice in).

e.g.
<?php
session_start();

if (isset($_SESSION["last_button_name"]))
{
    if ("fbutton" == $_SESSION["last_button_name"] and isset($_POST['sbutton']))
    {
        /* button 2 clicked after button 1 */
    }
}
// mind that the setting code for the session is missing in this example

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1