Drukowana wersja tematu

Kliknij tu, aby zobaczyć temat w orginalnym formacie

Forum PHP.pl _ XML, AJAX _ Dynamiczny Formularz zapamietywanie danych Jquery

Napisany przez: ufo1990 16.09.2020, 12:15:28

Mam poniższy kod który, który działa dobrze jednak mam problem w momencie przeładowania strony dane w dodanych polach input nie są zapisywane. Nie wiem czy obrobić to w jquery czy php. Proszę o pomoc.


  1. <http://december.com/html/4/element/script.html>
  2. $(document).ready(function () {
  3. var getControl=getCookie("countControls1");
  4. var max_fields_limit = 10;
  5. var x = 0;
  6. for(var i=1; i<=getControl; i++)
  7. {
  8. console.log(i);
  9. addControls();
  10. }
  11.  
  12. $('.add_more_button').click(function (e) { // Click event to add more fields
  13. addControls();
  14. });
  15. function addControls()
  16. {
  17. console.log(x);
  18. if (x < max_fields_limit)
  19. {
  20. x++;
  21. setCookie("countControls1",x,100);
  22. $('.input_fields_container').append('<div><input id="input1" placeholder="Imię i Nazwisko:" type="text" value=""/><a href="#" class="delete" >Usuń</http://december.com/html/4/element/a.html></http://december.com/html/4/element/div.html>');
  23. });
  24. }
  25. }
  26. $('.input_fields_container').on("click", ".delete", function (e) { // User click on remove text links
  27. $(this).parent('div').remove();
  28. x--;
  29. setCookie("countControls1",x,100);
  30. });
  31.  
  32. function setCookie(cname,cvalue,exdays) {
  33. var d = new Date();
  34. d.setTime(d.getTime() + (exdays*24*60*60*1000));
  35. var expires = "expires=" + d.toGMTString();
  36. document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  37. $("#div1").html("Add cookie = ",getCookie(cname));
  38. }
  39. function getCookie(cname)
  40. {
  41. console.clear();
  42. var name = cname + "=";
  43. var decodedCookie = decodeURIComponent(document.cookie);
  44. var ca = decodedCookie.split(';');
  45. console.log(ca);
  46. for(var i = 0; i < ca.length; i++)
  47. {
  48. var c = ca[i];
  49. while (c.charAt(0) == ' ')
  50. {
  51. c = c.substring(1);
  52. }
  53. if (c.indexOf(name) == 0)
  54. {
  55. console.log(c.substring(name.length, c.length));
  56. return (c.substring(name.length, c.length));
  57. }
  58. }
  59. return "";
  60. }
  61. });
  62. </http://december.com/html/4/element/script.html>

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)