0

I have texbox and dropdown list which is populated from mysql database.I want to change textbox value using dropdown list, without refreshing the page. Here is my code and Thanks in Advance.

<select name="select" id="dropdownlist1">
     <option id="0">-- Select the Company --</option>
           <?php
              require("dbcon.php");

        $getallcompanies = mysql_query("SELECT * FROM ifcandetails6");

        while($viewallcompanies = mysql_fetch_array($getallcompanies)){
             ?>
 <option id="<?php echo $viewallcompanies['tcuid']; ?>"><?php echo $viewallcompanies['tcname'] ?></option>
                <?php
                      }
                  ?>
              </select>

Here is my Input field code:

<input type="text" id="field1" value="<?php echo $viewallcompanies['tcname']?>" disabled/>
1
  • mysql_* is EVIL. Please google it first Commented Jul 5, 2015 at 18:16

1 Answer 1

1

Use following

   $(document).ready(function(){
    $("#dropdownlist1").change(function(){
        $("#field1").val($(this).val());
    });
   }); 

As you can do it on front side itself, you dont need to change in your PHP code. Add the following code on DOM ready.

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

3 Comments

@MuhammedParveezKhushaali , if it solves your problem , you can accept answer.
i want to retrieve the saved data from database using the dropdown list.. but in this code i am getting the same value in inputbox what i am selecting in dropdown list..
But you told .I want to change textbox value using dropdown list. Please First clarify the Question by editing it. There is Edit button.

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.