Jump to content

update html page real time


rohitb

Recommended Posts

i have 1 html page and 2 php files.. below are the codes

 

index.html

 

here user inputs the value in the text field of the form

<html>
<head>
<title>A BASIC HTML FORM</title>
</head>
<body>

<Form name ="form1" Method ="POST" Action ="callput.php">

<INPUT TYPE = "TEXT" VALUE ="Enter Nifty Spot Price" Name ="spotprice">
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Next->">

</FORM>

</body>
</html>

callput.php

 

depending on the user input value we calculate and give the user 2 more text boxes to fill values

<?php
$spotPrice = 1.0 * $_POST['spotprice'];
if($spotPrice%100>=0 && $spotPrice%100<40){
            $callStrikePrice=floor($spotPrice/100)*100 + 100;
            $putStrikePrice=floor($spotPrice/100)*100 - 100;
        }else if($spotPrice%100 >=40 && $spotPrice%100<=60){
            $callStrikePrice=floor($spotPrice/100)*100 + 100;
            $putStrikePrice=floor($spotPrice/100)*100;
        }else{
            $callStrikePrice=floor($spotPrice/100)*100 + 200;
            $putStrikePrice=floor($spotPrice/100)*100;
        }
?>

<Form name ="form1" Method ="POST" Action ="trend.php">
You Entered Nifty SpotPrice as <input type="text" name="spot" style="border:none;width:40px;background-color:#000000;color:yellow;font-weight:bold;text-align:center" value="<?php echo $spotPrice?>"/><br><br>
Enter price for Nifty <input type="text" name="something" disabled="" style="border:none;width:40px;background-color:#000000;color:yellow;font-weight:bold;text-align:center" value="<?php echo $callStrikePrice?>"/> CE <input type="text" name="callRate" size="10"><br><br>
Enter price for Nifty <input type="text" name="something1" disabled="" style="border:none;width:40px;background-color:#000000;color:yellow;font-weight:bold;text-align:center" value="<?php echo $putStrikePrice?>"/> PE <input type="text" name="putRate" size="10">

<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Calculate Trend->">

</FORM>

trend.php

 

depending on what value user has entered we give him the final result

<?php
$spotPrice = 1.0 * $_POST['spot'];
echo"$spotPrice<br><br>";
$callStrikePrice = 1.0 * $callStrikePrice;
$callRate = 1.0 * $_POST['callRate'];
echo"$callRate<br><br>";
$putStrikePrice = 1.0 * $putStrikePrice;
$putRate = 1.0 * $_POST['putRate'];
echo"$putRate<br><br>";
$actualCallRate = ceil(100.0 * (((($callStrikePrice - $spotPrice) - ($callStrikePrice - ($callStrikePrice+$putStrikePrice)/2.0))/($callStrikePrice - $spotPrice)) + 1) * $callRate);
$actualPutRate = ceil(100.0 * (1 - (((($callStrikePrice+$putStrikePrice)/2.0 - $putStrikePrice) - ($spotPrice - $putStrikePrice))/($spotPrice - $putStrikePrice))) * $putRate);

$buyPercent = ceil(10000.0 * $actualCallRate/($actualCallRate + $actualPutRate));
$sellPercent =  ceil(10000.0 * $actualPutRate/($actualCallRate + $actualPutRate));

echo'The chances of Nifty Future going up is ' .$buyPercent/100.0.  ' % and going down is ' .$sellPercent/100.0. ' %';
if($buyPercent==$sellPercent){
            echo"<br/><h1 style='color:yellow'>TREND IS NEUTRAL</h1>";
        }else if($buyPercent>$sellPercent){
            echo"<br/><h1 style='color:green'>TREND IS UP</h1>";
        }else{
            echo"<br/><h1 style='color:red'>TREND IS DOWN</h1>";
        }
        
?>

the issue is im loading the pages individually ie first index.html then callput.php and then trend.php .. is it possible to get the outputs on same index.html 

Edited by rohitb
Link to comment
Share on other sites

Yes you could make the form submit on the same page using  action="<?php echo $_SERVER['PHP_SELF'];?>"

 

To display values dynamically it would be best to use either Javascript or even Ajax.. Google it.

 

Also to display and hide certain form elements you could use CSS combined with PHP to hide/show elements when certain conditions are met

Edited by HippoZoned
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.