I have an issue trying to populate a price list for use in order processing. Would appreciate your help and any advice. The page should allow a user to either select the set cost of a service charge ($10.01 for brake pads) using CHECKBOX OR type in a CUSTOM PRICE amount for the customer. Test data ($10.01 for brake pads) is ok to the screen from the db, now just trying different ways to get form input field to function in CHECKBOX OR CUSTOM PRICE scenario. I’m relatively experienced with PHP but not with jquery. I’ve found some other similar code marked ‘PHP method’ and ‘JQuery method’ as possible options. Once visually set on screen, the input will be treated the same and saved as fields, added for total cost etc. I’m looking for the simplest way to implement while at bare knowledge of javascript and jquery & learning both.
The partially working link is as shown:
from the database, currently assigning each value to order before processing form. On submit, would reassign vars when input=“” or ==“0”;
$row_rsActiveServices = mysql_fetch_assoc($result);
$ordpatch=$row_rsActiveServices['bus_patch'];
$ordplug=$row_rsActiveServices['bus_plug'];
$ordalignment=$row_rsActiveServices['bus_alignment'];
$ordmuffler=$row_rsActiveServices['bus_muffler'];
PHP method {{{{
<input type="checkbox" name="chk[]" value="<? $row_rsActiveServices['bus_patch']; ?>" <?php if(isset($_POST['chk']['A'])) echo 'checked="checked"'; ?>/>A
<input type="checkbox" name="chk[]" value="<? $row_rsActiveServices['bus_plug']; ?>" <?php if(isset($_POST['chk']['B'])) echo 'checked="checked"'; ?>/>B
<input type="checkbox" name="chk[]" value="<? $row_rsActiveServices['bus_alignment']; ?>" <?php if(isset($_POST['chk']['C'])) echo 'checked="checked"'; ?>/>C
<input type="checkbox" name="chk[]" value="<? $row_rsActiveServices['bus_muffler']; ?>" <?php if(isset($_POST['chk']['D'])) echo 'checked="checked"'; ?>/>D
<input type="checkbox" name="chk[]" value="A" <?php if(isset($_POST['chk']['A'])) echo 'checked="checked" *echo '; ?>/>A
<!-- repeat this code for each service, we assume that servicesid is unique for each service: -->
<input <?php if (!(strcmp($row_rsActiveServices['showinfooter'],"y"))) {echo "checked=\\"checked\\"";} ?> name="checkbox[<?php echo $row_rsActiveServicess['servicesid']; ?>]" type="checkbox">
<input type="hidden" name="checkbox_mark[<?php echo $row_rsActiveServices['servicesid']; ?>]" value="1">
JQUERY METHOD: Perhaps use .show if checkbox "checked {{{
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
</script>
}}}
JAVASCRIPT METHOD: Using a button rather than checkbox to change the value of an element
{{{{
<p id="demo">
JavaScript can change the content of an HTML element.
</p>
<script>
function myFunction()
{
x=document.getElementById("demo"); // Find the element
x.innerHTML="Hello JavaScript!"; // Change the content
}
</script>
<button type="button" onclick="myFunction()">Click Me!</button>
}}}}} END JAVASCRIPT METHOD
LAST STEP, UPDATING THE DB
Gather the information:
if(isset($_POST['checkbox_mark'])){
mysql_select_db($database_db, $db);
// the value (servicesid) is passed in hidden input's key, therefore
// the value of the input itself is irrelevant ($dummy)
foreach ($_POST['checkbox_mark'] as $value => $dummy) {
$option = isset($_POST['checkbox'][$value]) ? 'y' : 'n';
$query = "UPDATE services SET showonwebsite='$option' WHERE servicesid = $value";
$Result = mysql_query($query, $db) or die(mysql_error());
}
}