Link to home
Start Free TrialLog in
Avatar of JaimeJegonia
JaimeJegoniaFlag for United States of America

asked on

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);

     }
Avatar of third
third
Flag of Philippines image

if you are submitting on the same page, just put your function on the onload event.

<body onload="addSku()">
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
Avatar of JaimeJegonia

ASKER

thanks to everyone who answered
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.