Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Script Calculates In Other Browsers, But Not in IE

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Script Calculates In Other Browsers, But Not in IE

Postby diehard » Fri Nov 23, 2012 6:50 am

Hi people, I have a little problem with this script. The script works perfect on all other browsers, but not with Internet Explorer (all versions).

The standard value of the totals is 0 and when using IE it keeps standing on 0. It won't change when selecting another option.

With other browsers, like Opera, Firefox and Chrome, it calculates and works fine.

Anyone an idea what the problem is? I can't find the solution.

Code: Select all
<form method="post">
 <table>
      <tr>
 <td>
 <select name="select1" id="select1">
 <?php
 $query = mysql_query("SELECT `product`, `price`, `setup`, `id` FROM `database_select1` WHERE `type` = 'select1' ORDER BY `id` ASC");
  while($row = mysql_fetch_object($query)){
  {
   $id = $row->id;
   $setup = number_format($row->setup, 2, ',', '.');
   $price = number_format($row->price, 2, ',', '.');
   }
  echo "<option value=\"$id\">$row->product $setup </option>";
    }
   mysql_free_result($query);
 ?>
 </select>
 </td>
 </tr>
 <tr>
 <td>
 <select name="select2" id="select2">
 <?php
 $query = mysql_query("SELECT `product`, `price`, `id` FROM `database_select2` WHERE `type` = 'select2' ORDER BY `id` ASC");
  while($row = mysql_fetch_object($query)){
  {
   $id = $row->id;
   $price = number_format($row->price, 2, ',', '.');
   //
   if($_GET['select2'] == $row->product){
  echo "<option value=\"$id\" selected=\"selected\">$row->product -> $price </option>";
    }
  else{
    }
  echo "<option value=\"$id\">$row->product -> $price </option>";
    }
   }
   mysql_free_result($query);
   ?>
 </select>
 </td>
 </tr>
 <tr>
 <td>
 <select name="term" id="term">
  <option value="1">1 Month</option>
  <option value="3">3 Months</option>
  <option value="6">6 Months</option>
 </select>
 </td>
 </tr>


<tr>
<td>Total costs:</td>
<td><input type="text" name="totalcost" id="totalcost" value="0"/></td>
</tr>
<tr>

<td>Total setup:</td>
<td><input type="text" name="totalsetup" id="totalsetup" value="0/></td>
</tr>
</table>
</form>

<!--START PHP VAR1 - Defining selectbox variables (crossmatch value-price): line 153 - 225-->
<?php
#Defining "costs" variable 
$costsarray = '';
   $query = mysql_query("SELECT `price`, `id` FROM ` database_select1` ORDER BY `id` ASC");
   while($row = mysql_fetch_array($query)){
   $id = $row['id'];
   $price = $row['price'];
   
   $costsarray.= "$id : $price, ";
  }
  $costsarray = trim($costsarray, ', ');
mysql_free_result($query);

#Defining "setup" variable
$setuparray = '';
   $query = mysql_query("SELECT `setup`, `id` FROM `database_select2` WHERE `setup` > 0 ORDER BY `id` ASC");
   while($row = mysql_fetch_array($query)){
   $id = $row['id'];
   $setup = $row['setup'];
   
   $setuparray .="$id : $setup, "; 
  }
  $setuparray = trim($setuparray, ', ');
mysql_free_result($query);
?>

<!--END PHP VAR1 START automatic recalculation (Javascript + jQuery)-->
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
//START Javascript F1 - Function to format raw output to EUR
function formatDollar(num) {
    var p = num.toFixed(2).split(".");
    return  p[0].split("").reverse().reduce(function(acc, num, i, orig) {
        return  num + (i && !(i % 3) ? "." : "") + acc;
    }, "") + "," + p[1];
}
//END Javascript F1

//START Javascript VAR2 - Defining variables and filling arrays
 (function($)
 {
 //standard costs
 var costs = {<?php echo $costsarray; ?>}
 //setup costs
 var setup = {<?php echo $setuparray; ?>}
//END VAR 2

//START OnChange activity declaration for selectbox
  $("#select1").change(function(){calc_and_show_total();})
  $("#select2").change(function(){calc_and_show_total();})
 
  $("#term").change(function(){calc_and_show_total();})
//END OnChange declaration

//START Javascript F2 - Calculating all selected variables 
function calc_and_show_total()
  {
   //monthly costs
   var term  = $("#term").val();
   var select1  = costs[$("#select1").val()];
   var select2   = costs[$("#select2").val()];
   var costssum  = (select1+select2)*term
 
   //setup costs
   var sselect1  = setup[$("#select1").val()];
   var setupsum = sselect1
 }
 
//Format currency (Function F1)
var coststotal = formatDollar(costssum);
var setuptotal = formatDollar(setupsum);
//Print to input field "total"
   $("#totalcost").val(coststotal);
   $("#totalsetup").val(setuptotal);
  }
//end print
//initialize our total
  calc_and_show_total();
 
 })(this.jQuery);
</script>
diehard
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Nov 23, 2012 6:49 am

Re: Script Calculates In Other Browsers, But Not in IE

Postby seandisanti » Fri Nov 23, 2012 2:11 pm

make sure you have javascript enabled in your install of IE. The php is executed serverside so the browser doesn't matter. The javascript is the only thing that is browser dependent.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Script Calculates In Other Browsers, But Not in IE

Postby diehard » Sat Nov 24, 2012 2:31 am

seandisanti wrote:make sure you have javascript enabled in your install of IE. The php is executed serverside so the browser doesn't matter. The javascript is the only thing that is browser dependent.



Thank you for your reply.

Javascript is enabled in my install of IE. Checked it. That wasn't the problem.
diehard
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Nov 23, 2012 6:49 am


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.