• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 686
  • Last Modified:

JavaScript: preserve fields after refresh

below is a javascript function which dynamically appends some fields to a form.
Using a submit button:
<input type = "submit" value = "More on this date" name = "more" onClick="AddText();">

i want to preserve these added fields if the page refreshed after clicking this button. Is this possible?
I really need your help. thanks.

-------------------------------------------------------------------------------------
     var fieldCount = 2;  #the first two fields
     var fieldCount1 = 2;

    function addSku() {

       fieldCount++;
       fieldCount1++;

       var node=document.createTextNode("GEAR (Enter SKU): ");
       document.getElementById("fs").appendChild(node);

       var newFriend = document.createElement('input');
       newFriend.type = 'text';
       newFriend.size = '17';
       newFriend.value = '';
       newFriend.onFocus = this.value="";
       newFriend.name = 'sku' + fieldCount;
       newFriend.id = 'sku' + fieldCount;
       document.getElementById('fs').appendChild(newFriend);

       var node=document.createTextNode(" ");
       document.getElementById("fs").appendChild(node);

       var newFriend1 = document.createElement('input');
       newFriend1.type = 'checkbox';
       newFriend1.name = 'gear' + fieldCount1;
       newFriend1.id = 'gear' + fieldCount1;
       document.getElementById('fs').appendChild(newFriend1);
   
   var node=document.createTextNode(" Review?");
   document.getElementById("fs").appendChild(node);

var newFriend2 = document.createElement('br');
document.getElementById('fs').appendChild(newFriend2);

     }
0
JaimeJegonia
Asked:
JaimeJegonia
3 Solutions
 
thirdCommented:
if you are submitting on the same page, just put your function on the onload event.

<body onload="addSku()">
0
 
ZvonkoSystems architectCommented:
No, it is not possible. The HTTP protocol is a stateless protocol. Therefore is the browser loading into the window that what is sent for the URL. There is no state before and after the page.
So if you want to repeat some user actions then you need some onLoad function which will look for some cookies that are not cleared on page form onSubmit action and try to analyze what you have to recreate on the page. But that is definitely not a behavior and design that I would recommend to you.
0
 
shaggy_the_sheepCommented:
Hi

Instead of using a submit button why dont you just use a normal button to fire the event. You could then use javascript to dynamically create the new rows without leaving the page

Richard
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
HonorGodCommented:
As noted above, HTTP is stateless.  So, in order to have this information "preserverd", you could/should save information into cookies.
0
 
radnorCommented:
If someone fills out an form and did not add all info or something was incorrect, you want to display back to the what they typed  -  is that correct?????  

(reload the form with original info intact?)

Do you have PHP avail?
0
 
JaimeJegoniaAuthor Commented:
thanks to everyone who answered
0
 
JaimeJegoniaAuthor Commented:
i used a button instead, so definitely the page would not be refreshed. It has an "onclick" attribute which calls a function in javascript to retrieve the data from the fields. javascript-perl connection is done through ajax.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now