2014-07-28 09:57


  • php
  • html
  • javascript

I have a web form that contains a drop down box that is populated by a request to a MySQL server with php, and a text box. The value in the text box is currently passed off to another page for processing. This all works fine but as there are a lot of submissions with the same value being passed through I've decided to implement the drop down box within the form to allow a user to select from the options that have been submitted previously.

What I would like is when the user clicks on a value in the drop down box that the value is used to populate the text box in the webform. I'm having trouble pulling this value out. I'm assuming that it requires an onClick/onSelect listener to be implemented but I'm not entirely sure how to do this. Any help would be greatly appreciated!

edit for code, currently I'm just trying to get the value to echo to the page as a proof of concept, but it will eventually need to go into the text box.

 <script type="text/javascript">
function moveToTextBox()
    echo $("#dropDownBox option:selected").text(); 

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

        Enter Asset Type<br/>
        <select name="currentItems" onUpdate="moveToTextBox()" id="dropDownBox">
            $pdo = Database::connect();
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $sql = "SELECT item FROM all_Items";
                echo "<option value=\"item1\">" . $row['item'] . "</option>";
        <input type="text" name="newItem" id="textId"><span class="error"> <?php echo $newItemError;?></span>
    <input type="submit" name="submit" value="Submit"> 
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享