Create a input button inside js function

Create a input button inside js function

I call my js function from HTML code from another file. Now I would like to create a input button on page using createElement() in my called function. I used something like this but doesn't seems to work. Lets show is the function being called function show(){ var element=createElement('button'); element.setAttribute('id', 'show'); element.appendChild(document.createTextNode('Button')); } what is the right way

View Answers

July 18, 2011 at 10:47 AM

I call my js function from HTML code from another file. Now I would like to create a input button on page using createElement() in my called function. I used something like this but doesn't seems to work. Lets show is the function being called

function show(){

    var element=createElement('button');
    element.setAttribute('id', 'show');
    element.appendChild(document.createTextNode('Button'));

}

what is the right way


July 18, 2011 at 1:13 PM

<html>
  <script>
function addRow(){
  var ptable = document.getElementById('ptablePerson');
  var lastElement = ptable.rows.length;
  var index = lastElement;
  var row = ptable.insertRow(lastElement);

  var cellText1 = row.insertCell(0);
  var element = document.createElement('input');
  element.type = 'text';
  element.name = 'person' + index;
  element.id = 'person' + index;
  element.size = 30;
  cellText1.appendChild(element);

  var cellText2 = row.insertCell(1);
  var element = document.createElement('input');
  element.type = 'text';
  element.name = 'person' + index;
  element.id = 'person' + index;
  element.size = 30;
  cellText2.appendChild(element);

  var cellText3 = row.insertCell(2);
  var element = document.createElement('input');
  element.type = 'button';
  element.value='Button';
  element.name = 'person' + index;
  element.id = 'person' + index;
  element.size = 30;
  cellText3.appendChild(element);

  document.getElementById("psize").value=index;
  }
</script>
<form >
<input type="hidden" name="psize" id="psize">
<table style="border:1px solid #000000;" bgcolor="#efefef" 
  id="ptablePerson" align="center">
<tr>
<td><input type="text" name="person1"  id="person1" size="30" /></td>
<td><input type="text" name="person1"  id="person2" size="30" /></td>

<td><input type="button" name="person1" value="Button" id="person4" size="30" /></td>
</tr>
</table>
<table align="center">
 <tr><td></td><td><input type="button" value="Add" onclick="addRow();" /></td></tr>
</table>
</form>
</html>

Ads









Related Tutorials/Questions & Answers:
Create a input button inside js function
Create a input button inside js function  I call my js function from HTML code from another file. Now I would like to create a input button on page.... Now I would like to create a input button on page using createElement() in my
Java Function for block inside a block
Java Function for block inside a block  Write a function in Java that attempts to place a set of squares of varying widths into another, larger... the positions for each input square in the larger box
Advertisements
Java Function for block inside a block
Java Function for block inside a block  Write a function in Java that attempts to place a set of squares of varying widths into another, larger... the positions for each input square in the larger box
user defined function inside a jsp
user defined function inside a jsp  how to write a user defined function inside a jsp page
create a button
create a button  i have created button inhtml but my jsp is not working,so can u guide me
button to accept user input
button to accept user input  private void jButton1ActionPerformed... the radiobutton and spinner.The user input does not show on my Studentinfo.mdb...); JButton button=new JButton("Submit"); text=new JTextField(15
is it possible to add a button inside an autocomplete jquery ui plugin?
is it possible to add a button inside an autocomplete jquery ui plugin?  is it possible to add a button inside an autocomplete jquery ui plugin? My... code for the button gets populated in the input field
Create a Program that Calculates Input
Create a Program that Calculates Input   Create a program that takes user input and does a calculation with it, then prints the results back for the user. This could include like a sales tax calculator, or a tip calculator
Create Button in CSS
Create Button in CSS  Can anyone help me to create a button in CSS HTML
function error too many input arguments
function error too many input arguments  function error too many input arguments
Accessing dynamically created variables inside a function
Accessing dynamically created variables inside a function  Hi, I'm... smoothly but my problem arises when I attempt to pass this variable to a function in the following way. public function InsertUpdate($uid,$update,$uploads,$pid
How to Create Button With TableView in iphone
How to Create Button With TableView in iphone  My requirement is i am creating one button. when i press the button TableView will display... on the button can u please send me the code i want to create converter app. thanks
How to create file from input values in Jframe ?
How to create file from input values in Jframe ?  hi i m doing my project using java desktop application in netbeans.i designed a form to get the user's academic details and on clicking the submit button,it displays all
How create an overlay button on different containing div
How create an overlay button on different containing div  How to create an overlay button on different containing div
Create Round Button in Java swing
Create Round Button in Java swing In this tutorial, we are going to create a button of round shape. Java2D APIs and Java Swing make it easy to implement... static void main(String[] args) { JButton button = new CreateRoundButton
How would you create a button with rounded edges?
How would you create a button with rounded edges?   How would you create a button with rounded edges?   Hi, Here is the answer, We can create rounded edge button in two way's, The first thing is to know
How to Create Button on Frame
How to Create Button on Frame       In this section, you will learn how to create Button on ... will show a simple command button labeled with the text "Submit" when
to change the styleclass color of <apex:outputlabel > onclick button function in javascript
to change the styleclass color of onclick button function in javascript  in the below code if user enters null value and click on save button...; } function checkvalidity() { if(document.getElementById("{!$Component.page1.form1.user
In JSP page, inside a javascript function, can I place a java code using scriptlet tag?
In JSP page, inside a javascript function, can I place a java code using... not empty. Inside the javascript function closeWind(), I make a call... checkListValue() using scriptlet tag inside the javascript function closeWind
How to change HTML button onclick to autoclick - javascript function
How to change HTML button onclick to autoclick - javascript function  Can any one give me a block of code to change the HTML button onclick to autoclick. The method must be in Java Javascript
How to change HTML button onclick to autoclick - javascript function
How to change HTML button onclick to autoclick - javascript function  Can any one give me a block of code to change the HTML button onclick to autoclick. The method must be in Java Javascript
List the names of classes used to create button and text box in Java.
List the names of classes used to create button and text box in Java.  List the names of classes used to create button and text box in Java
How to change the value of a variable which is set in jsp (by jstl method) by calling the function from js?
) by calling the function from js?  How to change the value of a variable which is set in jsp (by jstl method) by calling the function from js? I set... the value of 'name1' as "Edit User" when calling the editUser function which
Create Subpackages (i.e. A Package inside another package)
Create Subpackages (i.e. A Package inside another package... inside an another package. The packages that comes lower in the naming hierarchy... "subpackage". The naming convention defines how to create a unique
HTML Button Size
The Tutorial illustrate an example from HTML Button size. In this Tutorial we create... button. The difference between the element and button created with the input element...HTML Button Size      
input
input  a java program that will exchange the last names of two students that were input by a user
function
function  difference between function overloading and operator overloading
Calling a function
Calling a function  Hi, I have a function xyz() in php code. When a button is clicked it should execute that particular function for that i have...; <input type="button" name="submit" value="Submit"/> <
program to create student report using java applet,read the input using text boxesand generate the grades..?
program to create student report using java applet,read the input using text boxesand generate the grades..?   sir plz give me java applet codes for above question
jquery button click
to create a button event in JQuery. You can edit it as per your requirement. In Header...; <input id="Button1" type="button" value="button" />...jquery button click  jquery button click - I have created a button
How to create simple HTML Form?
HTML Form Tutorial: How to create simple HTML Form? In web application input... by by HTML. There are many different types of input elements such as text, button... such as text, button, radio button, select box and many others can be used to create

Ads