Answer the question
In order to leave comments, you need to log in
How to get the value for the fields from the server?
Good evening, comrades!
Using the "Submit" button sent the form data to the server.
But how to make it so that when you click on the "Add field" button, the fields contain values ​​​​that have already been sent?
<!DOCTYPE html>
<html>
<head>
<title>!DOCTYPE</title>
<meta charset="utf-8">
</head>
<body>
<form id="forma" action="#" method="post">
<div class="div">
<button type="button" id="add">Добавить поле</button>
<button>Отправить</button>
</div>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
current = 1;
$("#add").click(function() {
current++;
$("#forma").append("<div class='div'>Поле:<input type='text' id='input' size='10' name='avon' value=''></div>");
var avon = $("#input").attr("name");
var avon_current = avon + current;
$("#input").attr("name", avon_current);
var id = $("#input").attr("id");
var idkod_current = id + current;
$("#input").attr("id", idkod_current);
});
});
</script>
<?php
echo @$_POST["avon2"] . "<br>";
echo @$_POST["avon3"] . "<br>";
echo @$_POST["avon4"] . "<br>";
?>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question