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> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.