0

Hello sir/mam Inline Code Example Here

i am a student and working on php and javascript but i have a very little knowledge of javascript
i am stcuk in my project
i want to calculate total of two variables which are defined in two different javascript function
here is my code please help me

checkout_new.php

 <html>
<head>
<script type="text/javascript">
function showUser(str)
{
var plan= "<? print $plan ?>";
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }

else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    var obj3 = document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    var obj2 = document.getElementById("txtHint1").innerHTML=xmlhttp.responseText;
alert(obj2); 
alert(obj3);
var c = parseInt(obj3) + parseInt(obj2);
alert(c);
document.getElementById('subtot').innerHTML = c;

}
  }
xmlhttp.open("GET","getuser_new.php?q="+str+"&plan="+plan,true);
xmlhttp.send();

}



function showUser1(str1)
{
var extension= "<? print $var ?>";

if (str1=="")
  {
  document.getElementById("txtHint1").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {

var obj2 = document.getElementById("txtHint1").innerHTML=xmlhttp.responseText;
alert(obj2);

    }
  }
xmlhttp.open("GET","getuser_new.php?q1="+str1+"&ext="+extension,true);

xmlhttp.send();

}


</script>


</head>
<body>



<td width="22%"><?php
        echo "<select name=\"ddl_period\" id=\"ddl_period\" onchange=\"showUser1(this.value); \" class=\"plan_duration\">"; 
        echo "<option size =5 selected>Select</option>";
        if(mysql_num_rows($result)) 
        { 
        while($row=mysql_fetch_assoc($result)) 
        { 
        echo "<option>$row[domain_extension_duration]</option>"; 
        } 

        } 
        else {
        echo "<option>No Names Present</option>";  
        } 
echo "</select>";
        ?></td>

<td width="10%">
<label id="txtHint1" class="plan_price" for="ddl_period" name="lbldomain"></label></td>
</tr>
<tr>
<td>
<hr width="880px" style="margin-left:5px; margin-top:-135px;"></td>
</tr>
</table>
<table width="250px" height="276" align="center">
<tr>
<td width="33%">


<input type="text" id="domain" name="domain" class="plan_name" value="<?php echo $_REQUEST['dname']; ?>"/>
<br />
<label name="lbl_domain" id="lbl2" style="border:thin; font-family:Arial, Helvetica, sans-serif; font-size:16px;">
<?php echo $_REQUEST['nm']; ?>
</label>


</label>
</td>
<td width="22%">
<?php
        echo "<select name=\"ddl_host_period\" onchange=\"showUser(this.value); \" id=\"ddl_host_period\" class=\"hosting_duration\">"; 
        echo "<option size =5 selected>Select</option>";
        if(mysql_num_rows($result1)) 
        { 
        while($row=mysql_fetch_assoc($result1)) 
        { 
        echo "<option>$row[website_plan_duration]</option>"; 
        } 

        } 
        else {
        echo "<option>No Names Present</option>";  
        } 
echo "</select>";
        ?>

</td>

<td width="10%">
<label id="txtHint" class="plan_price1" for="ddl_host_period" name="lblplan" ></label>

</td>
</tr>
<tr>
<td>
<hr width="880px" style="margin-left:5px; margin-top:-100px;">
</td>
</tr>

<tr>
<td colspan="2" align="right">

<script type="text/javascript" language="javascript">

function changeLabel() {

var total = obj1 + obj2; 

document.getElementById('subtot').innerHTML = total;

}

</script>


<table align="right" style="margin-top:-180px; margin-right:10px">
<tr><br><br>
</tr>
<tr>
<td width="130">
<label id="subtotal" style="color:#333333;"><b>Subtotal:</b></label> 
</td>
<td>



<label id="subtot" for="ddl_host_period" >
</label>
</td>
</tr>
<tr>
<td width="130">
<label id="tax" style="color:#333333;"><b>Tax(?):</b></label>
</td>
<td>
<label id="tax1">Rs. 0000.00</label>
</td>
</tr>
<tr>
<td width="130" style="border-top:1px solid #999900;background-color:#DEDEBE" height="40">
<label id="total_amt" style="color:#333333;"><b>Total Amount:</b></label>
</td>


</body>
</html>

getUser_new.php

<?php
$q=$_GET["q"];
$q1=$_GET["q1"];
$extension=$_GET["ext"];
$plan=$_GET["plan"];
//$str=$_GET["str2"];
$con = mysql_connect('localhost','betaonly_ow','mql4xC1a8FNp');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("betaonly_ow", $con);

$sql='select website_plan_total from website_price_calculation where website_plan_duration = "'.$q.'" AND website_plan_type = "'.$plan.'"';

$result = mysql_query($sql);

$row = mysql_fetch_assoc($result);
echo $t1= $row['website_plan_total'];
$sql1='select total from domain_price_calculation where domain_extension_duration = "'.$q1.'" AND extension_name = "'.$extension.'"';

$result1 = mysql_query($sql1);

@$row1 = mysql_fetch_assoc($result1);
echo $t2= $row1['total'];


?>


<?php 

mysql_close($con);
?>

Edited by Ezzaral: Code formatting.

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Biiim
0

little hard to read & work out what variables and what is even happening. Since you say you're learning, you should make it a habbit to format your code so it is easy to read eg. indent every opening and move back in on every close. It makes it much easier for yourself to find things and spot errors as well as the next person who has to read it

Variables declared in a function are only accessible within that function, so if you want them accessible outside of a function you need to declare them outside eg.

var value1 = 0;
var value2 = 0;
function func1(){
    //do something
    if(false){
        //indent
    }
    value1 = 15;
}
function func2(){
    //do something
    value2 = 34.6;
}
func1();
func2();
alert('value1: '+value1);
alert('value2: '+value1);
alert('multiplied: '+(value1*value2));
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.