Join Login


Create your own Social Network.
 PHP and JavaScript
 by jimwtpa - Jun 28, 2011

Let me start off by saying I am a newbie and have been watching the awesome tutorial videos that RiverCityGraphix has on youtube. They are the most clear and easy to follow videos. Thanks for all of the work you do on those!!

I am trying to do something that I am not sure if the direction I am going in can even be done or how I should tackle the problem.

What I am doing is loading my page and with a mysql_query I am filling in text fields using php, such as urlpanel1, imgpanel1, titlepanel1,urlpanel2, imgpanel2, titlepanel2

I then have above each section a pulldown list that I am populating with data from my sql table. I want to be able to select an item from the pull down and click a button and the (I am guessing) javascript or some type of function would be able to change the text fields urlpanel1, imgpanel1, and titlepanel1 based on which item I selected in the pulldown. So if I selected the 3rd item in the pull down it would find in the mysql database the url, img, and title whose ID=3 and place those values in document.myform.textarea1.value

What is the best way to go about this? Thanks.


Here is a piece of my code:

<?php
$prefetch1 = mysql_query("SELECT id,product_name,product_url,product_img,product_title FROM products");
?>



<strong>Preselect Panel #1:</strong></th>
<td width="729" bgcolor="#CCCCCC" ><select name="preselectpanel1" >
<?php
//for each row we get from mysql, echo a form input
while ($rowpanel1 = mysql_fetch_array($prefetch1)) {
echo "<option value=\"$rowpanel1[id]\">$rowpanel1[product_name]</option>\n";
} ?>
</select>
<label>
<input type="button" name="preselect1btn" id="preselect1btn" onClick="prefill_1()" value="Pre-Select" />
</label></td>
</tr>
<th valign="top" bgcolor="#FFFF00" scope="row">
<strong>URL for Panel #1:</strong></th>
<td width="729" bgcolor="#CCCCCC" ><input name="urlpanel1" type="text" onMouseOut="window.status = '';return true" onKeyDown="limitText(this.form.limitedtextarea,this.form.countdown,300);" onKeyUp="limitText(this.form.limitedtextarea,this.form.countdown,300);" value="<?php print $urlpanel1; ?>" size="100" id="urlpanel1" ></td>
</tr>
<tr>
<th valign="top" bgcolor="#FFFF00" scope="row">
<strong>Image for Panel #1:</strong></th>
<td width="729" bgcolor="#CCCCCC" ><input name="imgpanel1" type="text" onMouseOut="window.status = '';return true" onKeyDown="limitText(this.form.limitedtextarea,this.form.countdown,300);" onKeyUp="limitText(this.form.limitedtextarea,this.form.countdown,300);" value="<?php print $imgpanel1; ?>" size="100" id="imagepanel1"></td>
</tr>
<tr>
<th valign="top" bgcolor="#FFFF00" scope="row">
<strong>Title for Panel #1:</strong></th>
<td width="729" bgcolor="#CCCCCC"><input name="titlepanel1" type="text" onMouseOut="window.status = '';return true" onKeyDown="limitText(this.form.limitedtextarea,this.form.countdown,50);" onKeyUp="limitText(this.form.limitedtextarea,this.form.countdown,50);" value="<?php print $titlepanel1; ?>" size="50" id="titlepanel1"></td>
</tr>

<tr>
<th height="10" scope="row" valign="top"></th>
</tr>




jimwtpa
United States
Posts:2
Joined:Jun 28, 2011
 RE: PHP and JavaScript
 by RiverCityGraphix - Jun 28, 2011

Hi jimwtpa! Welcome to the forums!

I use something similar to this on my website. The way I have it set up is that I have a drop down menu on one page and once I click submit it takes me to a form page. It passes the variable from the first page to the second in the url. Then the second page can use that data to populate the drop down menus. If you are wanting all of this to happen on 1 page you will probably need to use jQuery which allows for things to happen in real time without a page refresh.


Be sure to subscribe on YouTube.

Do you take great photos? Consider selling them on Dreamstime.
RiverCityGraphix
United States
Posts:327
Joined:Nov 21, 2009
 RE: PHP and JavaScript
 by jimwtpa - Jun 28, 2011

Thanks for the response! I do need it to happen all on 1 page without a refresh. Can you point me in the right direction to what types of jQuery functions I need to look into?


jimwtpa
United States
Posts:2
Joined:Jun 28, 2011
 RE: PHP and JavaScript
 by RiverCityGraphix - Jun 28, 2011

I found this while I was searching around: http://elegantcode.com/2009/07/01/jquery-playing-with-select-dropdownlistcombobox/

That might get you started. It doesn't seem to show exactly what you are looking for, but it is changing dropdown menus based on what you select.


Be sure to subscribe on YouTube.

Do you take great photos? Consider selling them on Dreamstime.
RiverCityGraphix
United States
Posts:327
Joined:Nov 21, 2009
  
Home About Contact Forum Youtube Privacy Policy
Copyright © 2009-2011 RiverCityGraphix.All Rights Reserved.