Link to home
Start Free TrialLog in
Avatar of jagguy
jagguyFlag for Australia

asked on

javascript change option and populate a input box a php variable

Hi,

How do I populate an input box a php variable when I change an option in a dropdown box?
I am using cakephp and I need to add the textbox assignment in the 2 date fileds using  js as below
function myFunc(val) {
    if(val != 4) {
        document.getElementById("startdatebox").disabled = true;
        document.getElementById("enddatebox").disabled = true;
    } else {
        document.getElementById("startdatebox").disabled = false;
        document.getElementById("enddatebox").disabled = false;
    }
}


   echo $this->Form->input('dateRange', array('label' => 'Date Range','id'=>'dateRange',
                      'options' => $dateRange,'style'=>'width:150px','selected' => $dateSelect ,'onclick'=> 'myFunc(this.value)' ));
         
         echo $this->Form->input('startDate',array('id'=>'startdatebox','label' => 'Start Date','class'=>'datepicker', 
                    'type'=>'text','style'=>'width:100px;height:30px','value' => $datestart,'readonly' => 'readonly'));
            echo '</td>';
            echo '<td>';
            echo $this->Form->input('endDate',array('id'=>'enddatebox','label' => 'End Date','class'=>'datepicker', 
                     'type'=>'text','style'=>'width:100px;height:30px','value' => $dateend,'readonly' => 'readonly'));
        

</script>

Open in new window

Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

You seem to be mixing up your client-side code (javascript) with your server-side code (php), so it's not really clear what you need.

Can you please clarify exactly what you mean.
Avatar of jagguy

ASKER

I want to assign a textbox a date value when I change an option box. This value to assign is stored in php variable so how do I do this?
Javascript does not have access to PHP - one is server-side and one is client-side.

Tell us what you mean by an option box - there's no such thing in HTML.

Do you want to update a textbox when you change a select dropdown?

Still struggling to understand what you need
Avatar of jagguy

ASKER

Do you want to update a textbox when you change a select dropdown?

yes
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial