/    Sign up×
Community /Pin to ProfileBookmark

Javascript onFocus event with struts

Hi all

I am working on a J2EE application with Struts. The jsp that I am working on has four textboxes. What i am supposed to do is that with javascript the moment the focus goes to the second textbox I have to delete the value from the first text box . Similarly with focus on the 3rd text box, i have to delete the value from the 2nd text box and so on.

Please Please help me asap….

Thanks in advance

radz

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@HaganeNoKokoroNov 06.2004 — Something like <input type="text" name="box1" id="box1">
<input type="text" name="box2" id="box2" onfocus="document.getElementById('box1').value='';">
<input type="text" name="box3" id="box3" onfocus="document.getElementById('box2').value='';">
<input type="text" name="box4" id="box4" onfocus="document.getElementById('box3').value='';">
should do it. If you have to delete all textboxes before the current one <script type="text/javascript">
var boxes=["box1", "box2", "box3", "box4"]; //ids of the text boxes, in order.
function deleteBefore(box) {
for(var i=0; i<boxes.length; i++) {
if(boxes[i]==box.id) break;
document.getElementById(boxes[i]).value="";
}
}
</script>
<input type="text" name="box1" id="box1">
<input type="text" name="box2" id="box2" onfocus="deleteBefore(this);">
<input type="text" name="box3" id="box3" onfocus="deleteBefore(this);">
<input type="text" name="box4" id="box4" onfocus="deleteBefore(this);">
Copy linkTweet thisAlerts:
@senshiNov 06.2004 — You need Java and not this thread, this is javascript.

JSP is server-side as is struts and struts is to do with Apache servers so any struts issues, your in totally the wrong site unless an Apache Guru is viewing...
Copy linkTweet thisAlerts:
@HaganeNoKokoroNov 06.2004 — He's not wrong, he is asking about changing the content of text fields at the client-side using javascript. Just because his server-side is Struts doesn't mean he can't have some client-side code as well, and that is what he asked for. Struts can't change the content of one text field onfocus of another.

It's not a JSP/Struts question, it's a javascript question, and as such belongs in this forum.
×

Success!

Help @radz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...