Reputation: 29
I'm newbie to this field. I'm trying to pass data between two html pages. It works properly fine when I run it on my own computer but when I upload it in hosting server what I see is that it doesnot update the result. I have a form which is rate exchange form. I update new rate from here so it is updated on my main page. It is not working when someone else visits my link he doesnot see any rate that I have updated. Any help will be appreciated. Here is my code
<body><div class="profile" style="margin-top:100px;border-bottom: 4px ; border-color: #ed3330;">
<center>
<form action="">
<div style="padding-top: 20px;" class="record">My sale rate</div><br><input id="sale" step="0.0001" type="number" required>
<br>
<div style="padding-top: 20px;" class="record">My purchase rate</div><br><input id="purchase" step="0.0001" type="number" required><br>
<input class="submit" style="width: 200px;margin-top: 100px;" name="submit" type="submit" value="Click_To_update" onclick="myfunction()" >
</form></center></div>
</body>
<script>
function myfunction(){
var purchase =document.getElementById("purchase").value
localStorage.setItem("purchase",purchase)
var sale =document.getElementById("sale").value
localStorage.setItem("sale",sale)
}
</script>
</html>
This is my form where updated rate is shown
<script type="text/javascript">
let loop=0
var purchase =localStorage.getItem("purchase")
document.getElementById("buy").innerHTML=purchase
var sale=localStorage.getItem("sale")
document.getElementById("sell").innerHTML=sale
myfun ()
function myfun (){
if (loop%2==0){
$('#source_amount').keyup(function () {
var sum = 0;
$('#source_amount').each(function() {
sum =purchase* Number($(this).val());
sum=sum.toFixed(2)
});
$('#target_amount').val(sum);
});
}
else {
$('#source_amount').keyup(function () {
var sum = 0;
$('#source_amount').each(function() {
sum =Number($(this).val())/sale;
sum=sum.toFixed(2)
});
$('#target_amount').val(sum);
});
}
}
</script>
Upvotes: 1
Views: 96
Reputation: 2037
Each browser have a localStorage
session. So when you are setting the rates, the values will only be available in your browser.
That means, if you are trying for someone else in another computer to see the changes you did in your application, you will need to persist that data to a place where you can access from both computers.
For that you need either a database or another way to persist the data you want to display in the other browser.
Upvotes: 1