Help - PHP/MySQL query result

oldBastard

Expert Member
Joined
Jul 28, 2006
Messages
4,751
Reaction score
1,234
Location
Somewhere near your mom
Hi

Need some help on a PHP/MySQL query result on a submit form. I have created a dropdown menu fetching the data from a table. When the user select the code it must fill in the description in the text area automatically. Now here is my problem, or stumbling block, how the hell.

HELP :confused:

Code:
					<td><select name="scode1">
						<option>Please Select Code...</option> 
						<!-- Drop down --> 
						<?php 
							$username = "username"; 
							$password = "password"; 
							$db = "db"; 

							$link = mysql_connect(localhost,$username,$password); 
							@ mysql_select_db($db) or die("Could not connect to the desired database."); 
     
							$cquery = "SELECT DISTINCT code FROM spareParts"; 
							
							$cresult = mysql_query($cquery) or die(mysql_error());
							
							while($row = mysql_fetch_array($cresult)){ 
							echo '<option value="' .$row['code']. '">'. $row['code']. '</option>'  ; 
							} 
						?>
						</select></td>
					<td><input type="text" name=descrition1></td>
					<td><input type="text" name="quantity1"></td>
 
eish. i'd do it in javascript with an onchange event personally.
 
No AJAX necessary here if all you wanna do is take the value of your select and add it as the value to the description1 input text. AJAX is for when you want to request server-side script without refreshing the browser windows (asynchronous).

Use jQuery and add a simple line like below but first you need to fix the missing quote from the end of description1, spelling and add IDs to the fields:

$('#scode1').change(function(){
$('#description1').val($(this).val());
})

Checkout this link aswell:

http://api.jquery.com/change/
 
No AJAX necessary here if all you wanna do is take the value of your select and add it as the value to the description1 input text. AJAX is for when you want to request server-side script without refreshing the browser windows (asynchronous).

Use jQuery and add a simple line like below but first you need to fix the missing quote from the end of description1, spelling and add IDs to the fields:

$('#scode1').change(function(){
$('#description1').val($(this).val());
})

Checkout this link aswell:

http://api.jquery.com/change/

Just be careful of change() if you have to support IE. It's dodgy at best with IE7 (IMHO&E).
 
Just be careful of change() if you have to support IE. It's dodgy at best with IE7 (IMHO&E).

Cant check IE7 myself but IE6 works fine with mouse selection on change event and I know IE8+ is also fine.

I do see the mouse wheel scroll + change event may not work but apparently you could do something like below which would check your browser to assign the relevant event which supports IE6 mouse scroll change event:

$('#scode1').bind($.browser.msie ? 'propertychange': 'change', function(){
})
 
Top
Sign up to the MyBroadband newsletter
X