Click to See Complete Forum and Search --> : Dynamic reload on pricing page


NickG21
12-29-2006, 08:47 AM
hey everyone, i am looking to have my pricing page be able to dynamically reload if a symbol for a different currency is checked such as a Euro or Lyra etc.... i have some code below that begins to set up the functionality i am looking for but does not process correctly. if anyone has any idea where my errors are it would be appreciated
thanks in advance
Nick

<?php
$CurrencySymbols = array( 1 => "\$", 2 => "€", 3 => "£");
//Examples Made Up
$CurrencyExchangeRate = array(1 => 0, 2 => 0.6, 3 => 0.4);

$_SESSION["CurrencyID"] = isset($_SESSION["CurrencyID"]) ? $_SESSION["CurrencyID"] : 1;

$ItemPrice = 80;

$CurrencyPrice = $ItemPrice * $CurrencyExchangeRate[$_SESSION["CurrencyID"]];
echo $CurrencySymbols[$_SESSION["CurrencyID"]].$CurrencyPrice;

if(isset($_GET["currencyID"])){
if(is_numeric($_GET["currencyID"])){
$_SESSION["CurrencyID"] = $_GET["currencyID"];
}
}


?>

<html>
<body>
<form name="form1" action="converter.php" method="GET">
<a href='".$_SERVER['PHP_SELF']."?currencyID=1'>USD</a><br />
<a href='".$_SERVER['PHP_SELF']."?currencyID=2'>Euro</a><br />
<a href='".$_SERVER['PHP_SELF']."?currencyID=3'>British Sterling</a><br />
</form>
</body>
</html>

NightShift58
12-29-2006, 09:47 AM
I would change the currency selection process to a <SELECT> - which would be more flexible in terms of screen layout if you ever add more currencies to your list.

If you agree, then take a look at this thread with a simple and elegant solution by member "so_is_this": http://www.webdeveloper.com/forum/showthread.php?t=132844

NickG21
12-29-2006, 10:03 AM
i am more than willing to go ahead and try using a select statement but i am no type of javascript guru. i have less history with javascript than any other languages i use. i think what i am trying to say is that i am not sure how to go about writing the script, any tutorials or other references would be greatly appreciated, if not thank you for this anyway i'll start my research

NightShift58
12-29-2006, 10:09 AM
Have you really looked at the thread I mentioned?

This is all the Javascript you would need:
<select name="xxx" onchange="this.form.submit(); return true;">

NickG21
12-29-2006, 10:46 AM
i understand what you mean, but all that does is refresh the page i am on to the default, can i pass the value's of the option into a php variable that i can write my functions and statements for? i apologize if these questions sound ignorant, but right now that's exactly what i am.
thank you

NightShift58
12-29-2006, 10:57 AM
No, it doesn't just "refresh" the page. It "submits" the form in which the "select" is found and loads whatever page you have defined in "<form action='xxx.php'>".

In doing so, it will pass any variables in the <form> as so-called $_POST variables, which you can then use in the new instance of the script.

NickG21
12-29-2006, 11:24 AM
alright, that definitely makes a little more sense to me, i have figured it out using sessions and a little help from some tutorials and posts but thank you for your time and i am sure that you will read plenty of my posts in the future :)
thanks again

NightShift58
12-29-2006, 12:04 PM
Here's a link to a javascript example, which though a little more involved, would enable you to dynamically change the target URL for your <form>. I think it's simple enough to follow and integrate into your script, yet will do the job for you.

http://www.w3schools.com/js/tryit.asp?filename=try_dom_form_action