newbiehacker Posted August 7, 2006 Share Posted August 7, 2006 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] Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 7, 2006 Share Posted August 7, 2006 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) Quote Link to comment Share on other sites More sharing options...
newbiehacker Posted August 7, 2006 Author Share Posted August 7, 2006 maybe but I know you can do it with php right? Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 7, 2006 Share Posted August 7, 2006 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. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 7, 2006 Share Posted August 7, 2006 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! Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 7, 2006 Share Posted August 7, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.