All pastes #80870 Raw Edit

Unnamed

public text v1 · immutable
#80870 ·published 2006-07-06 22:05 UTC
rendered paste body
<?php
$a = $_GET['a'];
$b = $_GET['b'];
if ($a == "" || $b == "") {
    $total = "";
} else {
    $total = $a + $b;
}
$acc = $_SERVER['HTTP_ACCEPT'];
if (strpos($acc, 'message/x-jl-formresult')) {
    echo $total;
} else {
?>
<script src="xmlhttp.js" type="text/javascript"></script>
<script type="text/javascript">
 function calc() {
  frm=document.forms[0]
  url="index.php?a="+frm.elements['a'].value+"&b="+frm.elements['b'].value
  xmlhttp.open("GET",url,true);
  xmlhttp.onreadystatechange=function() {
   if (xmlhttp.readyState==4) {
    document.forms[0].elements['total'].value=xmlhttp.responseText
   }
  }
 xmlhttp.setRequestHeader('Accept','message/x-jl-formresult')
 xmlhttp.send()
 return false
}
</script>
<form action="index.php" method="get" onsubmit="return calc()">
<input type=text name=a value="<?php echo $a; ?>"> + <input type=text name=b value="<?php echo $b ?>">
 = <input type=text name=total value="<? echo $total ?>">
<input type=submit value="Calculate">
</form>
<?php } ?>