samedi 28 février 2015

js function to work onLoad with onClick in cakephp


In cakephp the below code works fine when I load a page and select an option to enable/disable textfields.


The problem is that when I refresh the page when I click a cakephp button elsewhere, the textfields are enabled again that were previously set to disabled.


What I need to to check on loading the page what option is selected. How do I get the the Onclick function to work as well as setting the textfield state whenever the page loads. The onload function below doesnt work.



window.onload=function(){
if(val != 3) {
document.getElementById("startdatebox").disabled = true;
document.getElementById("enddatebox").disabled = true;
} else {
document.getElementById("startdatebox").disabled = false;
document.getElementById("enddatebox").disabled = false;
}

} ​

function myFunc(val) {
if(val != 3) {
document.getElementById("startdatebox").disabled = true;
document.getElementById("enddatebox").disabled = true;
} else {
document.getElementById("startdatebox").disabled = false;
document.getElementById("enddatebox").disabled = false;
}

// alert( document.getElementById("dateRange").value);

}

...
echo $this->Form->input('startDate',array('id'=>'startdatebox','label' => 'Start Date','class'=>'datepicker', 'type'=>'text','style'=>'width:100px;height:30px','value' => $datestart));

echo $this->Form->input('endDate',array('id'=>'enddatebox','label' => 'End Date','class'=>'datepicker', 'type'=>'text','style'=>'width:100px;height:30px','value' => $dateend));




$selectoption=array(1=>'Today',0=>'Fortnight',2=>'Monthly',3=>'Custom Range');
echo $this -> Form -> input('dateRange',
array('id'=>'dateRange2','label' => '<h6>Date Range</h6>','type' => 'radio',
'value' =>$dateSelect,'options' => $selectoption, 'onclick'=> 'myFunc(this.value)'));




Aucun commentaire:

Enregistrer un commentaire