Jump to content

Fill a form from dropbox Pleas Help


newbiehacker

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]
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.