Jump to content

[SOLVED] Can you get a Submit button to act like a Checkbox?


Meissa

Recommended Posts

I'm sorry if this isn't as PHP-related as it could be, but it's all in the name of learning PHP:

 

 

*When you make a Checkbox in a form, you assign it a value...  then you hit another button to submit the value to be processed, right?

 

*When you make a Submit button, if you assign it a value, it displays the value on the button, but does not process that value.  (as far as I know)

 

???

 

I'm trying to get a Submit button to have a numeric value that I can program into it, that when it is clicked, it will enter that value into a variable and be able to be processed.  Basically eliminating the second click that a Checkbox makes you do.

 

I have an example on this page:

 

http://www.strangerthanfact.com/onyxia/formtest.php

 

After you open the page, hit REFRESH to clear the error...  And if several people are on this page at one time, the flatfile value will change sporadically.

 

Here's the important stuff from the code:

 

<html>
<body>

<?php 
if(isset($_POST['send'])) 
{ 
    $mod = $_POST['modifier'];
    echo "The last modifier was: ";
    echo $mod;
    echo "<br>";
}
?>

<hr>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> 
+1 
<input name="modifier" type="checkbox" id="modifier" value="1"> 
-1 
<input name="modifier" type="checkbox" id="modifier" value="-1"> 
<br>
<input type="submit" name="send" value="Calculate!">
</form>

<hr>

<center>
<h2>This is what I want to happen:</h2>
</center>
<font size="+1">
<br>
I want to be able to click these buttons only once and get them to perform the operations of the checkboxes above
<br>
<br>
Add || Subtract
</font>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> 

<button>
<input name="send" type="submit" id="modifier" value="1">
<img src="http://www.strangerthanfact.com/wowccg/heal-1.bmp">
</button>

<button>
<input name="send" type="submit" id="modifier" value="-1">
<img src="http://www.strangerthanfact.com/wowccg/dam-1.bmp">
</button>

</form>

</body> 
</html> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.