File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to call a struts tag using innerHTML

 
sanju sreedharan
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai everyone
i have one issue and i want to finish it within 2 days please help me ..when i press add same value returns instead i want a empty one..for example if i write enter the place=mahe and when i press add for writing the next one it repeat the same name mahe and again mahe like that..can you please help me in that issue and also one more issue is that when i press add it come one time and again if i press add instead 1 it comes 2 then 4..but i want each time 1..please help me .. i am sending the code along with this



<html>
<head>
<script type="text/javascript">
function addElement() {


var x=document.getElementById("myDiv")
var ni=x.innerHTML

var newdiv = document.createElement('div');

newdiv.innerHTML =ni;
x.appendChild(newdiv);


}
</script>
</head>
<body>

<a href="javascript:;" onklick="addElement()" id="theValue">Add</a>
<div id="myDiv">
<div>Enter your place:<input type="text"/> </div>
</div>

</body>
</html>

thanks in advance
sanju
[ November 29, 2008: Message edited by: sanju sreedharan ]
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this code working on your computer. Sorry to say but there is no evemt like onklick. IS this a typing mistake ?
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can customize this code as per your need. On click it adds only one Text Box.



function addElement() {
var x=document.getElementById("myDiv")
var ni=x.innerHTML
var newdiv = document.createElement('div');
newdiv.innerHTML = 'Enter your place: <input type="text"/>';
x.appendChild(newdiv);
}
[ November 28, 2008: Message edited by: Himanshu Gupta ]
 
sanju sreedharan
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that was just a spelling mistake..its working..

sanju
 
sanju sreedharan
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no actually i want to call the field under body tag...because i am using this function to call struts tag............

sanaj
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanju replace your function with the above one. The problem in your code was that every time when you take inner HTML it will give you the whole code (like say if you have 3 boxes then all 3 will come) and that was the reason of your problem.


Hope that the above code is easy to understand and implement.
 
sanju sreedharan
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much for the help

actually i know that code but i want to add something which come inside the body tag..i am trying to do that..any idea how to do it

sanju
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at what you are doing. You are adding the new div inside of the div you are copying. So the reason you are getting multiples is you are copying the new one each time.

Easiest way to change your code would be to add an element around it and append to that instead.



OR

Instead of copying innerHTML, you use create elements to build all of the info in there.

Eric
 
sanju sreedharan
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you eric for reply

ok one is clear i have one more doubt it is how can i get emply one when i press add....now i am getting the same value..you can see at my first message my problem..please tell me how to do it

thanks sanju
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

Using a title of "please help me" isn't very helpful.

Please go back and change your post to add a more meaningful subject by clicking the .
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic