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>









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
How to create an input box?
How to create an input box?  How to create an input box
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
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
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
create a button in html
create a button in html  How do I create a button which acts like a link
Create Button in CSS
Create Button in CSS  Can anyone help me to create a button in CSS HTML
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. (adsbygoogle
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 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 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...); } public static void main(String[] args) { JButton button = new
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,ADS_TO_REPLACE_1 We can create rounded edge button in two way's, The first thing
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below..."><label> <input name="radiobutton" type="radio" value...;<input type="hidden" name="hidden"><font color="white" size="5"><
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below..."><label> <input name="radiobutton" type="radio" value...;<input type="hidden" name="hidden"><font color="white" size="5"><
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below..."><label> <input name="radiobutton" type="radio" value...;<input type="hidden" name="hidden"><font color="white" size="5"><
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
how to take input table name in jsp to create table in mysql?
how to take input table name in jsp to create table in mysql?  how to take input table name in jsp to create table in mysql?   Hello Friend..."><input type="submit" value="Create Table"> </form> <% String
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
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
create text box by clicking button and submittong text in text box using submit
create text box by clicking button and submittong text in text box using...="4">NEW</font></font></b> <input type="button" value...">NEW</font></font></b> <input type="button" value="new
PHP date_create_from_format function
date_create_from_format  function The date_create_from_format function is also known as DateTime::createFromFormat. This function returns new DateTime object formatted according to the specified format.  Description
input
input  a java program that will exchange the last names of two students that were input by a user
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 create function download in web services with java? - WebSevices
How to create function download in web services with java?  I am a student in Viet Nam, I am coding a project j2me access web services to download a file.xml, anybody please help me how to creates function download in web
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
PHP Variable Outside Function
either outside the function or inside the function. If we declare a variable within... a variable outside the function, it will not seen inside the function.  Let's see... declared the variable outside the function and asking to print inside
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
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
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
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"/> <
function
function  difference between function overloading and operator overloading
Show text field & check input using jQuery
how to display 'text field' by a button click & check input using...Show text field & check input using jQuery In this tutorial, we will discuss about how to display 'text field' by a button click & check
HTML Button Size
and button created with the input element is that you can insert a content like image...HTML Button Size       Button in HTML is used to submit HTML page. Understand with Example ADS
Create UIButton Programmatically
and add a button on UIView dynamically. To create a button programmatically just... req. like you can create a simple RoundedRect button or a custom button if need..., we have successfully create a button but to add this button on view we need
Tag Inside Table in HTML
in HTML.In this code we define a HTML page and show you to create a tag inside a Table in HTML. The following tags used in code to create tag inside table in HTML... Tag Inside Table in HTML     
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
Button
Button  How to use image for button in JSF
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
i want to create an application with only a button which on click displays table from database using struts2 and hibernate on eclipse
i want to create an application with only a button which on click displays table from database using struts2 and hibernate on eclipse  please help me i have to submit this soon
javascript focus input
the user and a submit button. This button calls the function setfocus() which checks...;<br> <input type="button" id="name" onClick="setfocus()" value="Submit... javascript focus input
button
button  can i give multiple commands on click of a button? if yes how can i do that?? multiple commands can we retriving dat from database, capturing data, moving to next page.. etc
button
button  can i give multiple commands on click of a button? if yes how can i do that?? multiple commands can be retriving dat from database, capturing data, moving to next page.. etc
How to create simple HTML Login Page?
input fields such as text box, password field, radio button etc. to create...Simple HTML Login Page- Create a Simple HTML Login page and validate... to create simple login form in HTML. The login form is further validated

Ads