Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to add button to an HTML page in MVC using JAVASCRIPT???Please help soon
Posted
Updated 15-Nov-16 18:32pm
Comments
JoCodes 15-Apr-15 4:16am    
What you tried so far?

1 solution

Hello,

You can use below function for create dynamic input type using Javascript function.

JavaScript
$(document).ready(function () {

add("button");
});

C#
function add(type) {
  //Create an input type dynamically.   
  var element = document.createElement("input");
  //Assign different attributes to the element. 
  element.type = type;
  element.value = type; // Really? You want the default value to be the type string?
  element.name = type; // And the name too?
  element.onclick = function() { // Note this is a function
    alert("Demo");
  };

  var foo = document.getElementById("SpanName");
  //Append the element in page (in span).  
  foo.appendChild(element);
}
document.getElementById("btnAdd").onclick = function() {
  add("text");
};
<input type="button" id="btnAdd" value="Add Text Field">
<p id="fooBar">Fields:</p>


If you have any query regarding this solution, please ask me.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900