Skip to content
Browse files

how to make a dynamic button

  • Loading branch information...
1 parent ff0f855 commit edd0a17b0c97912a8547dbec0a48705565ec6785 Joe Armstrong committed
Showing with 40 additions and 0 deletions.
  1. +40 −0 test1.html
View
40 test1.html
@@ -0,0 +1,40 @@
+<HTML>
+<HEAD>
+<TITLE>Dynamically add Textbox, Radio, Button in html Form using JavaScript</TITLE>
+<SCRIPT language="javascript">
+function add(type) {
+
+ //Create an input type dynamically.
+ var element = document.createElement("input");
+
+ //Assign different attributes to the element.
+ element.setAttribute("type", type);
+ element.setAttribute("value", type);
+ element.setAttribute("name", type);
+
+ var foo = document.getElementById("fooBar");
+
+ //Append the element in page (in span).
+ foo.appendChild(element);
+
+}
+</SCRIPT>
+</HEAD>
+<BODY>
+<FORM>
+<H2>Dynamically add element in form.</H2>
+Select the element and hit Add to add it in form.
+<BR/>
+<SELECT name="element">
+ <OPTION value="button">Button</OPTION>
+ <OPTION value="text">Textbox</OPTION>
+ <OPTION value="radio">Radio</OPTION>
+</SELECT>
+
+<INPUT type="button" value="Add" onclick="add(document.forms[0].element.value)"/>
+
+<span id="fooBar">&nbsp;</span>
+
+</FORM>
+</BODY>
+</HTML>

0 comments on commit edd0a17

Please sign in to comment.
Something went wrong with that request. Please try again.