I want to create three checkbox say [] item1, []item2, []item3,
when I press checkbox for item1 the checkbox should stay checked and a input for data opens which when fed in calculates data, If I uncheck the data should disappear.
when I am using input type=submit, the code runs, but I want to do same using onchange or onclick and not have to use submit.
Guidance and help please and if possible a example,
Thanks
Youāll need front end code thenā¦ like JS or jQuery.
This part isnt clear to me:
- which when fed in calculates data,
More or lessā¦
you will output/create your page (your HTML markup).
Then add your jQuery code to have listeners check when any of the 3 checkboxes has a āchangeā
You then detect this āchangeāā¦ and then display the hidden input field(s) based on the checkbox change
Whats gets put into the input fieldā¦ is up to you (not clear)ā¦
Also what type of event(s) you want to trigger the: ācalculate this input dataā action.
Please find enclosed code
<form action ='' method='GET'>
<input type= 'checkbox' id='instal' name='instal' onchange='this.form.submit()'
<?php if(isset($_GET['instal'])) { echo 'checked'; } ?>>Install & Comm:
<input type= 'checkbox' id='delivery' name='delivery' onchange='this.form.submit()'
<?php if(isset($_GET['delivery'])) { echo 'checked'; } ?>>Delivery:
<input type= 'checkbox' id='discount' name='discount' onchange='this.form.submit()'
<?php if(isset($_GET['discount'])) { echo 'checked'; } ?>>Discount:
</form>
<?php
if(isset($_GET['instal'])) {
echo 'Install & Comm';
echo "<form name= 'instal' action ='' method='GET'>";
echo "<input type='decimal' name='total' size='10' >";
echo "<input type='decimal' name='ins_gst' size='2' value='' >";
echo "<input type='submit' name='submit' value='Submit' >";
echo "</form>";
$total=$_GET['total'];
$gst=$_GET['ins_gst'];
echo $total;
// Update to mysql ....
} else {
$total=0;
$gst=0;
// Update to mysql ....
}
if(isset($_GET['delivery'])) {
echo ' Delivery Charges ';
echo "<form name= 'instal' action ='' method='GET'>";
echo "<input type='decimal' name='total' size='10' >";
echo "<input type='decimal' name='ins_gst' size='2' value='' >";
echo "<input type='submit' name='submit' value='Submit' >";
echo "</form>";
$total=$_GET['total'];
$gst=$_GET['ins_gst'];
echo $total;
// Update to mysql.....
} else {
$total=0;
$gst=0;
// Update to mysql ....
}
if(isset($_GET['discount'])) {
echo 'Discount Percentage';
echo "<form name= 'instal' action ='' method='GET'>";
echo "<input type='decimal' name='ins_gst' size='2' value='' >";
echo "<input type='submit' name='submit' value='Submit' >";
echo "</form>";
$total=$_GET['total'];
$gst=$_GET['ins_gst'];
echo $total;
} else {
$total=0;
$gst=0;
// Update to mysql ....
}
?>