Create a input button inside js function

Ads

 
 

Share on Google+Share on Google+

Shashank Singh
Create a input button inside js function
2 Answer(s)      6 years and 2 months ago
Posted in : JavaScript Questions

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

Ads
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
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
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
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
function error too many input arguments
function error too many input arguments  function error too many input arguments
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 pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below...; <input name="radiobutton" type="radio" value="radiobutton" /> </label></td> <td width="350"><input type
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below...; <input name="radiobutton" type="radio" value="radiobutton" /> </label></td> <td width="350"><input type
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below...; <input name="radiobutton" type="radio" value="radiobutton" /> </label></td> <td width="350"><input type
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
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 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...="post"> Enter Table Name:<input type="text" name="table"><input type
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
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
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
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
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...;/font></font></b> <input type="button" value="new" onclick...;/font></font></b> <input type="button" value="new" onclick
input
input  a java program that will exchange the last names of two students that were input by a user
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