This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes how to call a struts tag using innerHTML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to call a struts tag using innerHTML" Watch "how to call a struts tag using innerHTML" New topic
Author

how to call a struts tag using innerHTML

sanju sreedharan
Ranch Hand

Joined: Nov 25, 2008
Posts: 48
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

Joined: Aug 18, 2008
Posts: 598

Is this code working on your computer. Sorry to say but there is no evemt like onklick. IS this a typing mistake ?


My Blog SCJP 5 SCWCD 5
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

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

Joined: Nov 25, 2008
Posts: 48
that was just a spelling mistake..its working..

sanju
sanju sreedharan
Ranch Hand

Joined: Nov 25, 2008
Posts: 48
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

Joined: Aug 18, 2008
Posts: 598

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

Joined: Nov 25, 2008
Posts: 48
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Nov 25, 2008
Posts: 48
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

Joined: Jan 10, 2002
Posts: 60804
    
  65

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 .


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to call a struts tag using innerHTML
 
Similar Threads
please help me
jsp exception while using logic:iterate
How to pass a javascript variable on a jsp to a servlet
Generating fields dynamically
Need Help With Dynamic text box in JSP