Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JavaScriptQuestions Create a input button inside js function
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Shashank Singh
Create a input button inside js function
2 Answer(s)      3 years and 5 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


Advertisement
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
user defined function inside a jsp
user defined function inside a jsp  how to write a user defined function inside a jsp page
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
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
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 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
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
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
function error too many input arguments
function error too many input arguments  function error too many input arguments
Create Button in CSS
Create Button in CSS  Can anyone help me to create a button in CSS HTML
create a button in html
create a button in html  How do I create a button which acts like a link
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
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
EXT JS
EXT JS   i want to create a grid in extjs to display data from mysql and if i want to edit the data i must update through extjs only and must update in mysql database. please help me with sample code. thank you
Configure Js request in Web.xml
; <td><input type="button" onclick="clickMe()"/></td>...Configure Js request in Web.xml  Hi all, I have 1 basic doubt...; function clickMe() { window.location.href="../controller/mainCtrl.jav
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 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
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
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
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 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
EXT JS
'}, ], data:tabData }); function dis(){ var ac=document.getElementById(check); alert(ac); } Ext.onReady(function(){ function renderCheck(value, p, record){ return Ext.String.format( '<input
Lightbox JS
Lightbox JS/font>       Lightbox JS is a simple, unobtrusive script used to overlay images on the current page. It`s a snap to setup and works on all modern browsers. Read full
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
calling servlet from JS and return response from servlet to JS
page when user clicks on a button i am calling a javascript function(eg myFunc..."; response.setContentType("text/plain"); response.getWriter().write(url); in js function...calling servlet from JS and return response from servlet to JS  hello
EXT JS
EXT JS  Hi, how to redirect from one extjs page to jsp page. i have a grid in extjs and in that grid i have a check box and i set the unique value for each checkbox. when i choose a check box and click the edit button it should
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
 

 

 

DMCA.com