Vote count:
-1
Hi I have a piece of code that works to populate a forms dropdown selections a specific columns data from my database...all based on a user email address all when you click a button. Now Im trying to figure out how to use this code for another button when clicked only instead of for a drop down menu selections...i need it to populate a text input, set a radio button option and select a dropdown menu selection.
Form my code... this piece:
while ($row = mysqli_fetch_assoc($result))
{
echo '<option value =" ' . $row['selections'] . ' ">' . $row['selections'] . '</option>';
}
...populates the dropdown menu im talking about with selections using info from my database.
I tried rebuilding this code (below) and using it to populate a text input, set a radio button option and select a dropdown menu selection but it dosnt work. Works fine on populating the dropdown menu with data from my database as selections but not to populate or set a radio button option or to select a dropdown menu selection.
Heres the code I'm using to try to populate my text input field , select a dropdown menu selection and set a radio button option...
Form
<form action="/">
<input id="invoiceidcopy" name="invoiceidcopy" type="text" value="sd156s1df5sd1"/>
<button id="submit-id">Prefill Form</button>
<input id="mile" name="mile" required="" type="text">
<input type="radio" id="q1" name="q1" value="x" />
<input type="radio" id="q1" name="q1" value="xx" />
<select id="extrafield5" name="extrafield5">
<option selected="selected" value="">Please select...</option>
<option value="PURCHASE">Order for Purchase</option>
<option value="REVIEW">Order for Review</option>
</select>
<button id="submit" type="submit" name="Submit">Submit</button>
</form>
Script
<script>
$(function(){
$('#submit-id').on('click', function(e){ // Things to do when 'Submit Id' button is clicked
var invoiceidcopy = $('#invoiceidcopy').val(); // Grab invoiceidcopy from text field
e.preventDefault(); // Prevent form from submit, we are submiting form down with ajax.
$.ajax({
url: "/tst/orders2.php",
data: {
invoiceidcopy: invoiceidcopy
}
}).done(function(data) {
$('#mile').append(data); // append results from orders2.php to select
$('#q1').append(data); // append results from orders2.php to select
$('#extrafeild5').append(data); // append results from orders2.php to select
});
});
});
</script>
orders2.php
<?php
// Create the connection to the database
$con=mysqli_connect("xxx","xxx","xxx","xxx");
// Check if the connection failed
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
if (isset($_GET['invoiceidcopy']))
{
$invoiceidcopy= $_GET['invoiceidcopy'];
$query = "SELECT mile
FROM seguin_orders
WHERE invoiceidcopy = '".($invoiceidcopy)."'";
$result = mysqli_query($con,$query);
while ($row = mysqli_fetch_assoc($result))
{
echo '<option value =" ' . $row['mile'] . ' ">' . $row['mile']
. '</option>';
echo '<option value =" ' . $row['q1'] . ' ">' . $row['q1']
. '</option>';
echo '<option value =" ' . $row['extrafield5'] . ' ">' . $row['extrafield5']
. '</option>';
}
}
?>
I know there several factors and variables im missing here...please excuse my ignorance...I've been trying to figure this out for a few weeks and I cant understand how to get this to work...my programming skills are not allowing me to make any progress...any help would be greatly appreciated...thanks in advance.
How to prefill form using database?
Aucun commentaire:
Enregistrer un commentaire