Page 1 of 1

PHP + Javascript to populate forms objects

Posted: Tue Feb 22, 2005 1:09 pm
by Draco_03
Hellow
my knowledge is very "basic" about php and Js
So i made a research on the net,

I found out how to populate a simple input texte from a Combo box.
Now I need to populate a combo box, FROM another combo box.
But the information comes from a db.

So this is my first attempt (i'm still reading about it)
I don't need the whole code, just some help finding it on my own.
Here's my attempt (don't laugh) :)

Code: Select all

<body>
<div id="section"> 
  <?php include ("includes/top_menu_en.html") ?>
  <div>
    <h1 id="titre">Skin Profile</h1>
  </div>
  <div id="texte"> blah blah blah yadda yadda blah blah blah blah blah blah blah blah blah blah blah blah
    <br />
    <br />
    <form name="profil_en" method="post" action="$_SERVERї'PHP_SELF']">
	<table width="300" border="0" cellpadding="0" cellspacing="0">
	<tr>
	<td><select name="part" class="lignes" onchange="fill_conds()"><option value="--">--</option>
	<?php
	$part_sql = "SELECT * FROM prof_part";
	$part_result = mysql_query($part_sql) or die(mysql_error());
	$part_numrows = mysql_num_rows($part_result);
	
	for ($i=0, $numrows=mysql_num_rows($part_result); $i<$numrows; $i++){
		$row = mysql_fetch_row($part_result);
		echo ("<option value="$rowї1]">$rowї1]</option>");
		}
		?>
		</select></td></tr>
		<tr>
		<td><select name="cond" class="lignes"><option value=""></option>
<script language="JavaScript" type="text/javascript">
		function fill_conds()
		{
		var fill=document.formsї0].part.optionsїdocument.formsї0].part.selectedIndex].value
		<?php
		$fill = fill;
		$cond_sql = "SELECT * FROM prof_cond WHERE part_name = $fill";
		$cond_result = mysql_query($cond_sql) or die(mysql_error());
		$cond_numrows = mysql_num_rows($cond_result);
		
		for ($i=0, $numrows=mysql_num_rows($cond_result); $i<$numrows; $i++){
		$row = mysql_fetch_row($cond_result);
		echo ("<option value="$rowї2]">$rowї2]</option>");
		}
		?>
		}
</script>
	</select></td>
		</tr>
	</table>
    </form>
  </div>
  <?php include ("includes/small_menu_en.html") ?>
</div>
</body>
So basically I'm to thw point where i need him to check in my database for the row where part_name = to whatever I selected in my combo box (being Face or Body).

I think that's it
If you need more info ask away

thx
PS : there is no more

Code: Select all

Tags?

Posted: Tue Feb 22, 2005 1:20 pm
by Burrito
if the info is coming from a db, you're going to either need to pull it all down on the original page load where you could then use JS to populate the other box. Or you could submit the form with the first drop down and then populate the second based on the value of the first.

Burr

Posted: Tue Feb 22, 2005 1:23 pm
by feyd
creating new options in a drop down is fairly simple. You make a new option object :: http://devguru.com/Technologies/ecmascr ... ption.html

Removing one is simple as well. delete it. Altering is also possible through the properties, as you will see on the DevGuru page above.


CoderGoblin submitted a Tutorial (hint) on using drop downs and databases.

Posted: Tue Feb 22, 2005 1:44 pm
by Draco_03
feyd wrote:CoderGoblin submitted a Tutorial (hint) on using drop downs and databases.
Thanks, but i searched for codergoblin post (224 match) and although i didn't checked them all, there is nothing i found.. :/
I also checked in tutorials of course.

And thank you for the links I'm working on it right now :)

Posted: Tue Feb 22, 2005 1:48 pm
by feyd
It was posted by myself, as CoderGoblin didn't have rights to add it at the time.

I'll get around to changing it to his thread at some point.. ;)

Posted: Tue Feb 22, 2005 1:54 pm
by Draco_03
Owwwwww,

And the title was pretty clear too, hehe
I still missed it because I just looked at the author name.

silly me
:P

Oh and feyd, what happened to the php tags ?

Posted: Tue Feb 22, 2005 2:10 pm
by feyd

Code: Select all

[url=http://forums.devnetwork.net/viewtopic.php?t=29267]What the heck happned?[/url]