Jump to content


change data without refreshing


4 replies to this topic

#1 replaya

    Young Padawan

  • Members
  • Pip
  • 32 posts

Posted 07 November 2005 - 05:29 PM

Hi all,

I have a drop-down list box thats echo product sizes. I would like the price variable depending on the choosen product size within the list box to change without refreshing the page.

How would go about doing something like that, I was told by someone the only way of doing something like thats is throught javascript. Is that true ? or can it be done in php because I have idea when it comes to javascript.

Or alternatively have the page refresh, when the user clicks on a particular size in the drop-down box echo ing the correct price

your help is much appreciated, and thanks in advance

<?php 


$query = "SELECT products.prod_id, products.name, fprice.frmCode, fprice.frmPrice, fprice.frmSize FROM products INNER JOIN fprice ON products.code = fprice.frmCode AND products.prod_id = '$prodid'";

$results = mysql_query($query)
or die(mysql_error());
	
if ($query)
{	
echo "<select name='frmPrice'>";
while ($row = mysql_fetch_array($results)) 
{

// .$row['frmSize'] = the sizes of the product

$price = $row['frmPrice'];
echo "$price";
  echo "<OPTION VALUE=\"".$row["frmID"]."\">".$row["frmSize"]." </OPTION> ";
  }
echo "</select>";
}      
 ?>  
	
</td>
    <td width="22%"></td>
    <td width="22%"><?php echo $price; ?></td>
  </tr>
  <tr>
    <td colspan="4">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="4">quantity</td>
  </tr>


#2 Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

Posted 07 November 2005 - 05:45 PM

I think Javascript would do it, I know PHP wouldn't as PHP isn't executed until the page is reloaded, Javascript can change things after it's loaded ;)

However, I'm no coder so this is the end of my "sounding smart" speech <3

#3 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 07 November 2005 - 05:45 PM

AJAX <3
http://www.pixel2life.com/twodded/t_ajax_a..._to_send_data_/

#4 replaya

    Young Padawan

  • Members
  • Pip
  • 32 posts

Posted 07 November 2005 - 06:08 PM

bloody nora AJAX is going give some headaches, im still learning php java script:emoticon('<3')
smilie

#5 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 07 November 2005 - 06:09 PM

As avalance so elegantly said, AJAX ;)
http://www.sitepoint...-scripting-ajax
http://www.sitepoint...ke-command-ajax

It's interesting to get working, but once it gets going, it's like a dream.
But you could always try a javascript function to calculate the price, and not have to worry about the php (unless you use a database).

And if you know nothing about JavaScript, but you know a bit about PHP, then you know a bit of JavaScript <3

Also note, PHP is a server-side language, which means the server processes it. JavaScript is client-side... which means you process it.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users