Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Dynamiczny Formularz zapamietywanie danych Jquery
ufo1990
post 16.09.2020, 12:15:28
Post #1





Grupa: Zarejestrowani
Postów: 83
Pomógł: 0
Dołączył: 26.07.2019

Ostrzeżenie: (0%)
-----


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

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 28.03.2024 - 14:10