Jump to content


Photo

Fill a form from dropbox Pleas Help


  • Please log in to reply
5 replies to this topic

#1 newbiehacker

newbiehacker
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 07 August 2006 - 10:04 PM

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
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>


#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 07 August 2006 - 10:26 PM

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)
follow me on twitter @PHPsycho

#3 newbiehacker

newbiehacker
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 07 August 2006 - 10:32 PM

maybe but I know you can do it with php right?

#4 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 07 August 2006 - 10:38 PM

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.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#5 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 07 August 2006 - 10:52 PM

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!
follow me on twitter @PHPsycho

#6 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 07 August 2006 - 10:57 PM

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.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users