Jump to content

Archived

This topic is now archived and is closed to further replies.

newbiehacker

Fill a form from dropbox Pleas Help

Recommended Posts

I am trying to fill a text box from a dynamic select box and cant seem to figure it out. My goal is when the user selects a value from select box It creates a query based on the selection and fills my textbox fields. I think I need java script but I a very new at this PLEASE help here is what I have so far[code]function selectDistinct($tablename,$attributename,$dropdownname,$defaultvalue){

global $db;
$sql = "SELECT DISTINCT {$attributename} FROM {$tablename}";
$resultID = $db->query($sql);
echo "\n<select name=\"{$dropdownname}\">";
while($row = $resultID->fetchRow(DB_FETCHMODE_ASSOC))
{
$result = $row[$attributename];
if(isset($defaultvalue)&& $result == $defaultvalue)
echo "\n\t<option selected value =\"{$result}\">{$result}";
else
echo "\n\t<option value =\"{$result}\">{$result}";
echo "</option>";
}
echo "\n</select>";
}

echo "Roles: ";
selectDistinct("role","extension","roleselect","Add");
?>

<form name="form1" method="post" action= "addRole.php">
   
  <table border="1"  align=center  bgcolor=#EEEEEE>
  <td colspan="2" bgcolor=#CCCCCC>
        <tr>
            <td>RoleName:</td>
            <td><input type="text" name="extension" value="<?php echo $result;?>" /></td>
        </tr>
        <tr>
            <td>DND</td>
            <td><input type="radio" name="dnd" value="on" />On<input type="radio" checked name="dnd" value="off" />Off</td>
        </tr>
        <tr>
            <td>Paging</td>
            <td><input type="radio" name="paging" value="on" />On<input type="radio" checked name="paging" value="off" />Off</td>
        </tr>
<tr>
            <td>P:0</td>
            <td><select name="choice0"><option value="dest ">dest</option><option value="dtmf ">dtmf</option></select><input type="text" name="fkey_0"/></td>
        </tr>
        <tr>
            <td>P:1</td>
          <td><select name="choice1"><option value="dest ">dest</option><option value="dtmf ">dtmf</option></select><input type="text" name="fkey_1"/></td>[/code]

Share this post


Link to post
Share on other sites
You need AJAX kidda...

Don't panic - it doesn't take too long to learn W3C's ajax tutorial is a good place to start.

If you need any more help you can get me on msn (toonmariner@hotmail.com)

Share this post


Link to post
Share on other sites
The other way you could get something like that to work would be to fill a javascript array with all the possible results from the query first and write some javascript along with the form, with a function that fills the textbox from the corresponding array element, which gets called from the select menu's onchange event.

Share this post


Link to post
Share on other sites
using ajax would mean you did not have to do all that though! ;)

you don't want to have to grab all the possible options first - let the user see a nice clean html structure with minimal js.

it would still mean they needed js switched on mind!

Share this post


Link to post
Share on other sites
Yes, but that would mean having to learn Ajax! The user need not see anything, it really all depends on how many options there are. If it was, say, only 10 or 20, it's not a big deal to write out a javascript array with those 10 or 20 elements.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.