😆Create a form with dom with nested tags, Wrapping a set of DOM elements using JavaScript (ok)
C:\xampp\htdocs\code\test.html
<!DOCTYPE html>
<html>
<head>
<title> Create a Form Dynamically with the JavaScript </title>
</head>
<body style="text-align: center;">
<h1 style="color: green;"> GeeksforGeeks </h1>
<p> Click on the button to create a form dynamically </p>
<button onClick="GFG_Fun()"> click here </button>
<p id="GFG_DOWN"></p>
<script type="text/javascript">
// Create a form dynamically
var form = document.createElement("form");
form.setAttribute("method", "POST");
form.setAttribute("action", "/webhook/");
// Create an input element for form-group
var FG = document.createElement("div");
FG.setAttribute("class", "form-group");
// Create an input element for Label
var LB = document.createElement("label");
LB.append("顧客番号");
// Create an input element for Full Name
var FN = document.createElement("input");
FN.setAttribute("type", "text");
FN.setAttribute("class", "form-control");
FN.setAttribute("id", "UserID");
FN.setAttribute("placeholder", "顧客番号入力");
FN.setAttribute("name", "UserID");
FG.appendChild(LB);
FG.appendChild(FN);
// create a submit button
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "submit.php");
var s = document.createElement("input");
s.setAttribute("type", "submit");
s.setAttribute("value", "Submit");
// Append the full name input to the form
form.appendChild(FG);
document.getElementsByTagName("body")[0].appendChild(form);
</script>
</body>
</html>
PreviousHow to recursively fetch data from paginated API then combine into one array (ok)NextArray find, Tìm phần tử đầu tiên thỏa mãn điều kiện (ok)
Last updated
Was this helpful?
