Hi there,

I'm trying to use a dynamic drop down box to populate some input fields.. So far I can make the drop down box populate correctly. I can also link the input fields to an id in my table, however I'm not sure how to link that id with the id of the item chosen from the drop down box.

Basically, I want my users to be able to make a selection from the drop down box and have it fill in "type" and "shortrange" from the table. This is part of a larger form that is all submitted to another table at the end...

Here is what I have so far:

//this is my include to connect to the db.

$query="SELECT * FROM equipment";
$result = mysql_query ($query);

echo "<select name='weapon1'>";
echo "<option value='none'>---Select---</option>";

//this part dynamically fills in the dropdown
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt 
echo "<option value='weapon1'>$nt[name]</option>";
echo "</select>";

//this was my attempt at at least filling the input boxes with something, it'd be nice if we could just replace the 3 with something lol
$query2="SELECT * FROM equipment WHERE id = 3";
$result2 = mysql_query ($query2);

while($row = mysql_fetch_array($result2))

echo "<input type ='text' name = 'type' value = $type>";
echo "<input type ='text' name = 'shortrange' value = $shortrange>";

I plugged in id = 3, just to see what it'd look like, but I realize that won't work, I don't know java, but I might need that to keep the page from refreshing and wiping the information from the rest of the form, right? Any help is appreciated!

look into ajax. it should do what you want.

I figured out how to do something with php that'll work... but now I have another lil issue..
There are 2 tables, I can use this drop down to select from 1 table and enter the data into the 2nd table. That works just fine, but I need to make an edit page. Is there a way to set the default value from table #2?

<?php echo "<select name='weapon2'>";
echo "<option name='weapon2' value='$nt[name]'>$nt[name]</option>";
echo "</select>"; ?>

Relevent table information:
Table 1 - characters
field - weapon1

Table 2- equipment
field - name

I just need to know how to put the default value of the drop down as characters.weapon1 (where id = $id) followed by the results from list of all equipment.name

Any thoughts?

Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.