12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- var inputStructure = [
- {prompt: "Введите Фамилию",
- default_: "",
- field: "surname",
- placeholder: "surname",
- type: "text",
- },
- {prompt: "Введите Имя",
- default_: "",
- field: "name",
- placeholder: "name",
- type: "text",
- },
- {prompt: "Введите Отчество",
- default_: "",
- field: "fatherName",
- placeholder: "father name",
- type: "text",
- },
- {prompt: "Введите возраст",
- default_: "0",
- field: "age",
- placeholder: "age",
- type: "number",
- },
- ]
- var result = {};
- function jqInputAnything(result, inputStructure, value1, value2){
- document.write("<form>");
- for (var i = 0; i < inputStructure.length; i++) {
- document.write("<label>" + inputStructure[i].prompt + " </label><input type= '"+inputStructure[i].type+"' value='"+inputStructure[i].default_+"' placeholder='"+inputStructure[i].placeholder+"' /> <br />");
- }
- document.write("<p><input type='button' id='save' value='"+value1+"'/> </p> ");
- document.write("<input type='submit' id='reset' value='"+value2+"'/>");
- document.write("</form>");
-
- $("#save").click(function(){
- for (var i = 0; i < inputStructure.length; i++) {
- result[inputStructure[i].field] = $("input:nth-of-type("+(i+1)+")").val();
- }
- console.log(result);
- return false;
- });
- }
- jqInputAnything(result, inputStructure, "Сохранить", "Сбросить");
|