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

jagguyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
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.
0
jagguyAuthor Commented:
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?
0
Chris StanyonWebDevCommented:
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
0
jagguyAuthor Commented:
Do you want to update a textbox when you change a select dropdown?

yes
0
Chris StanyonWebDevCommented:
OK. Here's a very basic way to do it:

The HTML:

<select id="mySelect">
    <option value="">Please Select...</option>
    <option value="option1">Option 1</option>
    <option value="option2">Option 2</option>
    <option value="option3">Option 3</option>
    <option value="option4">Option 4</option>
</select>

<input type="text" id="myText" />

Open in new window


The jQuery:

$('#mySelect').change(function() {
    $('#myText').val( $(this).val() );
});

Open in new window


The Working Demo:

http://jsfiddle.net/ChrisStanyon/mzuagmx9/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.