I am working in the confines of a CMS system, which defines certain fields which can be used to make forms for use within the application in PHP.
The list function has the signature:
function inputBasicList ($id,$value = "",$list = array(), $displayName = NULL, $displayLabel = true)
I use it thusly:
$theinput = new inputBasicList("type",$therecord["paymenttype"],array("Cash"=>"cash","Credit"=>"credit"), "Payment Type");
Likewise, there is a checkbox, which has the signature:
function inputCheckbox($id,$value = false, $displayName = NULL, $disabled = false, $displayLabel = true)
I use it thusly
$theinput = new inputCheckbox("paid", $therecord["paid"], "Paid");
What I would like to do, is if the list is set to credit instead of the default cash, to automatically set the checkbox to true/checked.
I don´t think the CMS system allows a way to do this using any built in functions, and am wary of adding any javascript.
Is such a thing possible with just PHP?
Otherwise, how complicated would the javascript have to be to do such a thing?
edit:
The generated HTML from the phpBMS forms
<p class="big"><label for="type" class="important">Payment Type</label>
<br />
<select name="type" id="type" class="important" >
<option value="cash" >Cash</option>
<option value="credit" >Credit</option>
</select>
</p>
<p class="big">
<input type="checkbox" id="paid" name="paid" value="1" class="radiochecks" />
<label id="paidLabel" for="paid" >Paid</label>
</p>
It’s not possible to do such thing with PHP only, because PHP is run on your server. You need some code that is run on the client.
I believe that the first paramater
$idis used asidattribute for the elements? If I’m wrong correct me. If so you can do the following using the jQuery JavaScript Library:UDPATE
BMS is using Mootools, the JavaScript should like like this to work in mootools:
I would recommend using the mootools version of this snippet, but just for your interest, if you want to install jQuery, you can add the jquery.js into phpbms/common/javascript. Then you can edit phpbms/header.php to include this:
after the last
$tempjsarray[]add:then after
$phpbms->showJsIncludes();you need to include this, so jQuery works without problems besides mootools:If this doesn’t work, you should post what the html output looks like.