Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have java script code using html.
i want that whenever i run my code in browser i want the browser to display the previous values and not blank t fill values again.
how to do plz help.
thanx in advance.

<!DOCTYPE html>
<html>
<head>

<title>Generate Budget</title>
</head>
<script type="text/javascript">

function tableprint()
{

var numOfYears = Math.abs(document.getElementById('end').value -

document.getElementById('start').value);
var budget = Math.abs(document.getElementById('budget').value);
var i = 0;

var tableHtml = "";




for (i=0; i<=numOfYears; i++)
{tableHtml = tableHtml.concat("(");
tableHtml = tableHtml.concat(Number(document.getElementById

('start').value)+Number(i));
tableHtml = tableHtml.concat(":");
tableHtml = tableHtml.concat("Budget");
tableHtml = tableHtml.concat(":");
tableHtml = tableHtml.concat(budget/numOfYears);
tableHtml = tableHtml.concat(";");
tableHtml = tableHtml.concat("Forecast");
tableHtml = tableHtml.concat(":");
tableHtml = tableHtml.concat(Number(document.getElementById('for'+i).value));
tableHtml = tableHtml.concat(";");
tableHtml = tableHtml.concat("Actual");
tableHtml = tableHtml.concat(":");
tableHtml = tableHtml.concat(Number(document.getElementById('act'+i).value));
tableHtml = tableHtml.concat(")");

}
document.getElementById("form2").innerHTML =tableHtml;
}


function generateBudget()
{ var numOfYears = Math.abs(document.getElementById('end').value -

document.getElementById('start').value);
localStorage.setItem("Math.abs(document.getElementById('end').value -

document.getElementById('start').value)", numOfYears);
var budget = Math.abs(document.getElementById('budget').value);
localStorage.setItem("Math.abs(document.getElementById('budget').value)",budget)
var i = 0;

if( numOfYears < 1)
{
numOfYears = 1;
}

var tableHtml = "";
tableHtml = tableHtml.concat("");
for (i=0; i<=numOfYears; i++)
{
tableHtml = tableHtml.concat("");
}
tableHtml = tableHtml.concat("");
tableHtml = tableHtml.concat("");

for (i=0; i<=numOfYears; i++)
{
tableHtml = tableHtml.concat("");
}

tableHtml = tableHtml.concat("");
tableHtml = tableHtml.concat("");

for (i=0; i<=numOfYears; i++)
{
tableHtml = tableHtml.concat("");
}

tableHtml = tableHtml.concat("");
tableHtml = tableHtml.concat("");

for (i=0; i<=numOfYears; i++)
{
tableHtml = tableHtml.concat("");
}
tableHtml = tableHtml.concat("
");
tableHtml = tableHtml.concat(Number(document.getElementById

('start').value)+Number(i));
tableHtml = tableHtml.concat("
Budget");
tableHtml = tableHtml.concat(budget/numOfYears);
tableHtml = tableHtml.concat("
Forecast");
tableHtml = tableHtml.concat("<input type='text' name='for" +Number(i)+"'

id='for" + Number(i) + "' />");
tableHtml = tableHtml.concat("
Actual");
tableHtml = tableHtml.concat("<input type='text' name='act" +Number(i)+"'

id='act" + Number(i) + "' />");
tableHtml = tableHtml.concat("
");
tableHtml = tableHtml.concat("
<input type='button' name='submit'

id='submit' value='Submit' />
");

document.getElementById("form").innerHTML = tableHtml;


}

</script>

Start Year <input type="text" name="start" id="start" />
End Year

<input type="text" name="end" id="end" />
Budget <input type="text" name="budget" id="budget" />
<input type="button" name="generate" id="generate" value="Generate"

/>



<textarea id="form2">
</textarea>
</body>
</html>
this is the code
Posted
Updated 13-Oct-15 4:48am
v2
Comments
[no name] 13-Oct-15 10:45am    
Please provide more details what you want exactly. It is not clear.

If you tried with some code provide that as well.
Member 12045679 13-Oct-15 10:48am    
i have displayed the code.plz help..http://www.codeproject.com/script/Membership/View.aspx?mid=7478705
[no name] 13-Oct-15 10:51am    
Please describe what do you need exactly.
Member 12045679 13-Oct-15 10:55am    
i am asking that when i run this code in browser and after entering values in text field i am getting my table.i want that when i close the browser and again run my code i want the previous table with previous values to be displayed in the browserhttp://www.codeproject.com/script/Membership/View.aspx?mid=7478705
Wombaticus 13-Oct-15 10:56am    
Well, don't submit teh form with a submit button - use an ordinary button and add an onclick function to call teh javascript function

1 solution

The question you ask comes down to the same point: where will you store the data between browser sessions.

On commentator suggested cookies - that would work except, if the browser's set up like mine, it will delete them when it is closed. Also, what if a different user opens the browser: should they see the last values of the last user or their own last values -> and what happens if they switch browsers on the same machine?

You need a storage area that is not at the mercy, so far as possible, of the user's browser and settings. This really, then, requires you store the data on the server side instead of the client side. You could then store the data in a database or file, server side, and all of the problems in the previous paragraph go away.

I suggest php [Learn how here]

If this is to be user specific, you'll need some way to know which user is requesting the data.

As for "can you plz give me the code" - I leave that to you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900