0

hey guys i am building a form in which i want when a user select an option from the dropdown menus a text to be displayed and calculate the price.

The dropdown menu is:

<select id="recipient" name="recipient" tabindex="6" class="selmenu">  
            <option value="staff">Site Staff</option>  
            <option value="editor">Editor-in-Chief</option>  
            <option value="technical">Tech Department</option>  
            <option value="pr">Public Relations</option>  
            <option value="support">General Support</option>  
        </select>

and the other dropdown menu is:

<select id="recipient" name="recipient" tabindex="6" class="selmenu">  
            <option value="one">1</option>  
            <option value="two">2</option>  
            <option value="three">3</option>  
            <option value="four">4</option>  
            <option value="five">5</option>  
        </select>

What i want to do is when the user selects something from the first and the second menu i want a textfield to change dynamically... can anyone point me the way?

1
  • You have to listen onchange event on both select elements Commented Jun 20, 2014 at 9:57

2 Answers 2

1

only ajax/jquery could do that in combination of php step might be...

  1. onchange of any dropdown make a ajax request to php script.

  2. return the json response from php script

  3. use this response to either manipulate your form or display data on page.

Sign up to request clarification or add additional context in comments.

4 Comments

What does ajax here? OP doesn't mentioned interaction with server
@hindmost Strictly speaking OP has, 'PHP Dynamically' although it's obviously not actually required..
how ami going to do that??i really new in to those kind of stuff..if you could help me??
@hindmost - he does, OP requested PHP to do the calculation and that to happen dynamically. If it's PHP, the server has to do it, and if it has to be dynamic, then AJAX is the only way to retrieve the value without leaving the page.
1

you don't need to use php for this, it can all be done with jquery/javscript

an example using jquery is below (i had to rename your second select as you had re-used an ID):

$('.selmenu').change(function() {
  $('#output').text($('#recipient option:selected').text() + ' ' + $('#recipient2 option:selected').text());
})

output is the id of your textbox.

on a select value being changed, output will be filled with the selected value in both select controls

1 Comment

well it doesnt do anything and i dont know why??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.