Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

questions regards to qid=1585634

Status
Not open for further replies.

phpdonkey

Technical User
Mar 3, 2011
25
NL
thread216-1585634
hi! i was actually following along with the thread213-1585634
since i am doing the very same thing. im also a newby in the programming world, and i had some questions about this dropdown menu:


I also need to find a way to have 5 text fields populate dynamically from the user selection of a drop down menu value. I have seen many numbers of threads about this even other websites, but none are working for me. untill i came accros this website with the repective posts .
I have a drop down menu that is dynamically filled with the company names from a mySQL database. (this works) What I need is for the text input fields (aTitle, aStory, aFooter, aGraphic, visiblePage.(visiblePage is an enum value in db for my radio buttons to swtich it visible or hidden)) to fill with the information that belongs to the record in that table and have it loaded id from the drop down selection.

my db table about look like this :
aboutId | aboutTitle | aboutStory | aboutGraphic | aboutFooter | visiblePage

since i like DW i use it to help me along the way , i have managed to get this far while following lesSje and vacunita. i dont want to be a copy cat i just want to learn php much better since i want to make my own website with it.
can anyone tell me what i am doing wrong and how to populate my inputs based on what information i have in my about table?

my code look like this :

php:
Code:
<?php require_once('../Connections/db_config.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_db_config, $db_config);
$query_rsAbout = "SELECT aboutId, aboutTitle, aboutStory, aboutGraphic, aboutFooter, visiblePage FROM about ORDER BY aboutId ASC";
$rsAbout = mysql_query($query_rsAbout, $db_config) or die(mysql_error());
$row_rsAbout = mysql_fetch_assoc($rsAbout);
$totalRows_rsAbout = mysql_num_rows($rsAbout);

?>


html form + js :
Code:
<head>
<script type="text/javascript">
	function selectItem(selObj)
	{
		var aboutItemArray=new Array();
		aboutItemArray.<?php echo $row['aboutId']; ?> = new Array();
		aboutItemArray.<?php echo $row['aboutId']; ?>.aboutTitle=<?php echo $row['aboutTitle'];?> 
		aboutItemArray.<?php echo $row['aboutId']; ?>.aboutStory=<?php echo $row['aboutStory'];?> 
		aboutItemArray.<?php echo $row['aboutId']; ?>.aboutFooter=<?php echo $row['aboutFooter'];?> 
		aboutItemArray.<?php echo $row['aboutId']; ?>.aboutGraphic=<?php echo $row['aboutGraphic'];?> 
		aboutItemArray.<?php echo $row['aboutId']; ?>.visiblePage=<?php echo $row['visiblePage'];?> 
		

	
		
		
		var id = selObj.options[selObj.selectedIndex].value;
		document.getElementById('aboutTitle').value = aboutItemArray[id]['aboutTitle'];
		document.getElementById('aboutStory').value = aboutItemArray[id]['aboutStory'];
		document.getElementById('aboutFooter').value = aboutItemArray[id]['aboutFooter'];
		document.getElementById('aboutGraphic').value = aboutItemArray[id]['aboutGraphic'];
		document.getElementById('visiblePage').value = aboutItemArray[id]['visiblePage'];
		
	}

</script>
    
</head>



    <form name="aboutForm" method="POST" action="<?= $_SERVER['PHP_SELF']?>">
    <select name="about" class="aboutListmenu" id="about" onchange="selectItem(this)">
	 <?php do
	 {
	?>
    <option value="<?php echo $row_rsAbout['aboutId']?>"
	<?php if (!(strcmp($row_rsAbout['aboutId'], $row_rsAbout['aboutId'])))
	{
		   echo "selected=\"selected\"";} ?>>
			 <?php echo $row_rsAbout['aboutTitle']?></option>
				 <?php
    }
	
				 while ($row_rsAbout = mysql_fetch_assoc($rsAbout));
				 $rows = mysql_num_rows($rsAbout);
				           if($rows > 0) 
						   {
							   mysql_data_seek($rsAbout, 0);
							   $row_rsAbout = mysql_fetch_assoc($rsAbout);
							}
					?></select>
                    
     
			<label>About Title:</label>
			<input name="aboutTitle" type="text" id="aboutTitle" />
			  		
		  <label>About Story:</label>
		<textarea name="aboutStory" id="aboutStory" cols="20" rows="5"></textarea>
				
			<label>Footer text:</label>
			<input name="aboutFooter" type="text" id="aboutFooter" value="" />
			
        <label>Current Preview Graphic:</label>
        <img name="aboutGraphic" src="../content/about/<?php echo $row_rsAbout['aboutGraphic']; ?>" class="floatLeft_padding35" />
     

			
	<label><input type="radio" name="1" value="1" />Visible</label>
	<label><input  type="radio" name="0" value="0" />Hidden</label>
			
		<input name="submit" type="submit" id="Submit" value="Submit" />
		
        
          <input type="hidden" name="status" value="" />
		<input type="hidden" name="MM_update" value="">
    </form>

 
yeah it actually worked . i just added this to the Array, works fine now. only the upload i will try to make it work. then it all comes together finally. thank you very much for helping me out this far. for now i will be back to see if i can get this thing to work. heheh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top