0

I have 3 checkboxes:

<label><input type="checkbox">100%</label>
<label><input type="checkbox">50%</label>
<label><input type="checkbox">25%</label>

and one textbox1 that have fix value

<?php 
    $sampleValue= "200.35"
?>
<input type="text" class="form-control" id="sampleOfsample"  readonly="readonly" value="<?php echo $sampleValue ?>" >

If the checkbox check one it will get the % the value of $sampleValue and it will echo the amount at the same textbox.

How can I achieve this?

Thanks...

Sergey Sklyar
  • 1,902
  • 1
  • 15
  • 27

1 Answers1

3

I think you use only PHP without JavaScript and need to transfer data from one file to another. I assume you have form like this:

<form method="POST" action="fileName.php">
    <label><input type="checkbox" name='checkBoxOne'>100%</label>
    <label><input type="checkbox" name='checkBoxTwo'>50%</label>
    <label><input type="checkbox" name='checkBoxThree'>25%</label>
    <input type="Submit" value ="Submit"/>
</form>

Now what happens on the back-end side (fileName.php)

$checkBoxOne = $_POST["checkBoxOne"]
$checkBoxTwo = $_POST["checkBoxTwo"]
$checkBoxThree = $_POST["checkBoxThree"]

You check which one is filled and input into field`s value like:

<input type="text" class="form-control" id="sampleOfsample"  readonly="readonly" value="<?php echo $sampleValue ?>" >

Also, I would suggest to use "Select" element and not checkBox, because it will always send "one" value and you won't have to check each checkbox values.

Giulio Bambini
  • 4,695
  • 4
  • 21
  • 36