• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

java/html how to add fields when we click button

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
can you please explain me how to add textfields in a jsp page when i click a button .if i click a button three times three buttons should be added to that jsp page.
thanks in advance
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you need to tell us a bit more about what you need. Presumably these buttons are supposed to do something when they are clicked? Do they need different names? different text?
There are two basic approaches to this sort of problem:
1. The round-trip approach: when the button is clicked, the form is submitted to itself. The JSP contains a bean which counts the number of times the "add" button has been clicked, and generates that many button declarations to the output stream when the page is rendered.
2. The JavaScript approach: when the button is clicked, it runs sone JavaScript which modifies the document object model to add another button to the form.
It's not at all clear which of these might be appropriate to your situation.
 
giri shetty
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need the second Approach
 
giri shetty
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Frank,
i need the second approach , when i click a button every time one text field should be added to that jsp page.
thanks
 
Frank Carver
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to do this in JavaScript, then it's not really got anything to do with JSP. With this in mind I have moved this thraed to our HTML and JavaScript forum. Please continue the discussion there.
 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by giri shetty:
Hi guys,
can you please explain me how to add textfields in a jsp page when i click a button .if i click a button three times three buttons should be added to that jsp page.
thanks in advance


Do you want to add textfields or button.
There are two ways to add element dynemically.
(1) using document.write() property
(2) using document.createElement() property
Here is an example using (2) property.
------------------------------------
<html><head></head><body>
<form action=inputox.html name="form1">
<table>
<tbody id="tbody1">
<tr>
<td>
This is Row 1
<input type="button" value="Click to Add a Row" name="button1" >
</td>
</tr>
<tr id="lastTR">
<td id="lastTD">
This is Row 2
</td>
</tr>
</tbody>
</table>
<input type=submit>
</form>
<script>
textCount = 1;
function AddRow()
{
var tbody1 = document.getElementById("tbody1");
var lastTR = document.getElementById('lastTR');
var newTR = document.createElement('TR');
var newTD = document.createElement('TD');

tbody1.insertBefore(newTR, lastTR);
newTR.appendChild(newTD);
newTD.innerHTML="<input type=text name=textField" + textCount +">";
textCount++;
}
</script>
</body></html>
--------------------------------------
Please use on click proprty to call AddRow() function at first button ie. "button1". I was not able to post if i insert this property at button1.
Hope this will helpful to you.
[ January 26, 2004: Message edited by: himanshu patel ]
[ January 26, 2004: Message edited by: himanshu patel ]
 
So there I was, trapped in the jungle. And at the last minute, I was saved by this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic