Click here to Skip to main content
15,921,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HTML
<form class="clearfix" action="reg_account.php" method="post">
                            <div class="clearfix" style="padding-removed 34%;">
                                <input type="text" class="small-text" placeholder="User Name" name="name">
                            </div>
                            <div class="clearfix" style="padding-removed 34%; padding-removed 2px;">
                                <input type="text" class="small-text" placeholder="Registration ID" name="id">
                            </div>
                            <div class="clearfix" style="padding-removed 34%; padding-removed 2px;">
                                <input type="text" class="small-text" placeholder="Password" name="password">
                            </div>

                            <div class="clearfix" style="padding-removed 34%; padding-removed 2px;">
                                <input type="text" class="small-text" placeholder="Reference" name="reference">

                            </div>

                            <div class="clearfix" style="padding-removed 34%; padding-removed 2px;">
                                <input type="text" class="small-text" placeholder="Placement ID" name="placementid">
                            </div>
                            <br>
                            <div class="clearfix" style="padding-removed 34%;">
                                <select id="eproducts" name="cscf[producttype]" style="color: blue; width: 310px; text-align: center; background-color:captiontext">
                                    <!--                                    <option>------ Select Products ------</option>-->
                                    <?php echo "<option>---------------- Select Products ----------------</option>"; ?>
                                    <?php
                                    $query = "SELECT sl, types from `products`";
                                    $result = mysql_query($query) or die($query . "<br/><br/>" . mysql_error());
                                    while ($row = mysql_fetch_array($result)) {
                                        echo "<option value='" . $row['id'] . "'>" . $row['types'] . "</option>";
                                    }
                                    ?>
                                </select>
                                <input type="text" name="producttype" id="product_hidden">


                            </div>

                            <input type="submit" class="btn green" value="Registration">
                        </form>


JavaScript
<script>
            $(document).ready(function() {
                $("#eproducts").change(function(){
                    $("#product_hidden").val(("#eproducts").find(":selected").text());

                });
            });
        </script>


But, when I am pressing submit button its not posting product-type or when I am changing selected item its not showing value in textbox. please help me
Posted
Comments
Peter Leow 26-Nov-13 10:12am    
Please check the following:
$query = "SELECT sl, types from `products`"; // here it returns s1
echo "<option value='" . $row['id'] . "'>" . $row['types'] . "</option>"; // here it cannot find $row['id']

1. There is typo here:

JavaScript
$query = "SELECT sl, types from `products`";// here it returned s1


but

JavaScript
echo "<option value="" . $row[" id="] . "">" . $row['types'] . "</option>"; // here it said $row['id']


When submit button is clicked, it is the id not the types that is posted to the php script.

2. For the jQuery part, it should be:

XML
<script>
$(document).ready(function() {
   $( "#eproducts" ).change(function () {
       $( "#product_hidden" ).val($( "select option:selected" ).text());
    })
});
</script>
 
Share this answer
 
v2
Comments
Member 10261487 28-Nov-13 5:26am    
Yes, I have change this. But this still not working...
Peter Leow 28-Nov-13 6:55am    
Which part not working?
Member 10261487 19-Dec-13 14:32pm    
Thank you. I have done it.
You're naming your tag "cscf[producttype]" - which means you'll need to use that full name to retreive it in the target file. This could result in parsing errors as you're going to access it as
$_REQUEST['cscf[producttype]']

But the first "]" could be viewed as closing the index - giving an improper index and thus failed retrieval of the value.

Try a simpler (normal) name and see if that fixes your problem.
 
Share this answer
 
Comments
Peter Leow 26-Nov-13 12:27pm    
Hi, Balboos
You are right to spot this mistake, I missed it.
Member 10261487 19-Dec-13 14:32pm    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900