Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Populate textbox after selecting dropdown list

    The code below I am trying to use it to populate the textbox, I had a submit button but when i submitted all of the form was submit. How can i get the data to popukate the textbox without sending the entire form. Please any assistance would be really appreciated.

    enter code here

    <?php
    $savedName = "";
    require_once ('connect.php');
    //$id = "";
    $query = "SELECT * FROM customer ORDER BY custid";
    $result2 = mysqli_query($dbcon, $query);

    if(isset($_POST["loadbtn"]))
    {
    $id = (integer) $_POST["custid"];

    $sq = "SELECT custName FROM customer WHERE custid = '$id' ";
    $result = mysqli_query($dbcon, $sq);
    $details = mysqli_fetch_array($result);

    $savedName = $details["custName"];
    }

    ?>





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

    <?php
    $dropdown = "<select name='custid' >";

    while ($row = mysqli_fetch_assoc($result2))
    { $dropdown .= "\r\n<option value='{$row['custid']}'>{$row['custid']}</option>";
    }
    $dropdown .= "\r\n</select>";
    ?>
    <p><label class="label" for="custid">Customer ID:</label><?php echo $dropdown; ?>
    <span class="ferror">* <?php echo $equipErr; ?></span></p>


    <p><label class="label" for="cname">Customer Name:</label><input id="cname"
    type="text" name="cname" size="30" maxlength="70" value="<?php echo $savedName;
    ?> <?php if (isset($_POST['cname'])) echo $_POST['cname']; ?>" readonly="" ><span
    class="ferror">* <?php echo $custnameErr; ?></span> </p>
    ........

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,092
    Thanks
    23
    Thanked 594 Times in 593 Posts
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •