textfield value changes based on dropdown selection with PHP

Trying to get Mfr to change its values based on title from dropdown

Page 1 of 1

5 Replies - 3975 Views - Last Post: 15 April 2010 - 04:34 PM Rate Topic: -----

#1 Guest_JustinB*


Reputation:

textfield value changes based on dropdown selection with PHP

Posted 15 April 2010 - 11:27 AM

Please don't pay much attention to variable names.

	<TR>
		<TD align="right" valign="top" style="width:75px">			
			Title: 
		</TD>
		<TD valign="top" colspan="5" style="width:350px">
		<? 
			$query2="SELECT year FROM systems"; 

			$result2 = mysql_query ($query2); 
					
			echo "<select id='year' style='background:#FFFF99; width:340px' name=year value='' onchange='window.location.reload()'>Title</option>"; 

			while($nt2=mysql_fetch_array($result2)){
			echo "<option value=$nt2[year]>$nt2[year]</option>"; 
			}
			echo "</select>";
		?>
		</TD>
		<TD align="right" valign="top" style="width:75px">
			Landmark: 
		</TD>
		<TD valign="top"  style="width:340px" colspan="2" rowspan="3">
			<TEXTAREA style="background:#FFFFFF; width:340px" name="landmark" rows="3">
			</TEXTAREA>
		</TD>
	</TR>
	<TR>
		<TD align="right" valign="top" style="width:75px">			
			Mfr: 
		</TD>
		<TD valign="top" colspan="5" style="width:350px">
		<?
			$year = $_GET[year];
		
			$query3="SELECT system FROM systems WHERE year = '$year'"; 
			
			$result3 = mysql_query($query3); 
			
			$nt3=mysql_fetch_assoc($result3);

			echo "<INPUT style='background:#FFFF99; width:340px' type='text' name='mfr' id='mfr' value='$nt3[system]'> </INPUT>";
		?>
		</TD>
	</TR>



Is This A Good Question/Topic? 0

Replies To: textfield value changes based on dropdown selection with PHP

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2505
  • View blog
  • Posts: 8,565
  • Joined: 08-August 08

Re: textfield value changes based on dropdown selection with PHP

Posted 15 April 2010 - 02:56 PM

PHP is processed, then data sent to the user. This means that PHP cannot change drop downs until the next page refresh. You either want to use ajax or straight javascript.
Was This Post Helpful? 0
  • +
  • -

#3 Guest_Justinb*


Reputation:

Re: textfield value changes based on dropdown selection with PHP

Posted 15 April 2010 - 03:20 PM

im having the page refresh with an onchange function in the dropdown
Was This Post Helpful? 0

#4 jrm402  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 333
  • Joined: 18-March 10

Re: textfield value changes based on dropdown selection with PHP

Posted 15 April 2010 - 03:53 PM

I think it's because your reloading the page. What you need to do is use ajax to call a Javascript file that pulls selectedIndex of the drop downs and then send that value to a PHP file to process the query. The result is returned and the AJAX can populate the form appropriately.
Was This Post Helpful? 0
  • +
  • -

#5 duw  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-April 10

Re: textfield value changes based on dropdown selection with PHP

Posted 15 April 2010 - 04:17 PM

search for "chained dropdowns". jQuery or prototype have useful libraries for taking the pain out of ajax objects.
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2505
  • View blog
  • Posts: 8,565
  • Joined: 08-August 08

Re: textfield value changes based on dropdown selection with PHP

Posted 15 April 2010 - 04:34 PM

View PostJustinb, on 15 April 2010 - 05:20 PM, said:

im having the page refresh with an onchange function in the dropdown

If you don't want to use ajax/jquery then you need to use session variables to keep track of your php values between page refreshing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1