main.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. var inputStructure = [
  2. {prompt: "Введите Фамилию",
  3. default_: "",
  4. field: "surname",
  5. placeholder: "surname",
  6. type: "text",
  7. },
  8. {prompt: "Введите Имя",
  9. default_: "",
  10. field: "name",
  11. placeholder: "name",
  12. type: "text",
  13. },
  14. {prompt: "Введите Отчество",
  15. default_: "",
  16. field: "fatherName",
  17. placeholder: "father name",
  18. type: "text",
  19. },
  20. {prompt: "Введите возраст",
  21. default_: "0",
  22. field: "age",
  23. placeholder: "age",
  24. type: "number",
  25. },
  26. ]
  27. var result = {};
  28. function jqInputAnything(result, inputStructure, value1, value2){
  29. document.write("<form>");
  30. for (var i = 0; i < inputStructure.length; i++) {
  31. document.write("<label>" + inputStructure[i].prompt + " </label><input type= '"+inputStructure[i].type+"' value='"+inputStructure[i].default_+"' placeholder='"+inputStructure[i].placeholder+"' /> <br />");
  32. }
  33. document.write("<p><input type='button' id='save' value='"+value1+"'/> </p> ");
  34. document.write("<input type='submit' id='reset' value='"+value2+"'/>");
  35. document.write("</form>");
  36. $("#save").click(function(){
  37. for (var i = 0; i < inputStructure.length; i++) {
  38. result[inputStructure[i].field] = $("input:nth-of-type("+(i+1)+")").val();
  39. }
  40. console.log(result);
  41. return false;
  42. });
  43. }
  44. jqInputAnything(result, inputStructure, "Сохранить", "Сбросить");