Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6798053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:41:01+00:00 2026-05-26T18:41:01+00:00

Good day! I am trying to create a placeholder on my Struts2 Textfield. The

  • 0

Good day!

I am trying to create a placeholder on my Struts2 Textfield. The problem is, there is no built-in attribute for it. So i’ve decided to use javascript. But I don’t know how I can effect it on the struts text field.

Code for html textfield placeholder in javascript is as follow:

HTML: <input type="text" name="billingNameStreet" class="input" title="Street"/>

   <script type="text/javascript">
        $(':input[title]').each(function() {
            var $this = $(this);
            if($this.val() === '') {
                $this.val($this.attr('title'));
            }
            $this.focus(function() {
                if($this.val() === $this.attr('title')) {
                    $this.val('');
                }
            });
            $this.blur(function() {
                 if($this.val() === '') {
                     $this.val($this.attr('title'));
                 }
            });
        });
    </script> 

How can i effect it on my struts2 textfield:

<s:textfield label="TEST" name="test" cssClass="haha"/>
<s:textfield label="TEST1" name="test1" cssClass="haha1"/>
<s:textfield label="TEST2" name="test2" cssClass="haha2"/>

Or is there other way to create a placeholder in Struts2 textfield?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:41:02+00:00Added an answer on May 26, 2026 at 6:41 pm

    Here your jQuery code says that the selector is input elements with title attribute. In your struts2 tags, the title is not specified. In <s:textfield/> tag, you can use the title attribute which will be rendered to html title attribute. Hence, your code would need to be changed to something like:

    <s:textfield label="TEST" name="test" cssClass="haha" title="haha"/>
    <s:textfield label="TEST1" name="test1" cssClass="haha1" title="haha1"/>
    <s:textfield label="TEST2" name="test2" cssClass="haha2" title="haha2"/>
    

    You can use this document for future references:

    http://struts.apache.org/2.0.14/docs/textfield.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day, I've been trying to figure out a problem in my code. I'm
Good day, I've just started teaching myself VB.net. I'm trying to create a simple
Good day, i will try and explain myself here. i am trying to create
Good day everyone. I'm trying to figure out a way to use multiple flags
Good day Im trying to implement a read/write privilege in a folder but no
Good day! I am currently trying to create a background-image with multiple images on
Good Day All we are trying to do is inside a trigger make sure
Good day - several days have passed while i was trying to transport my
Good day, I am trying to copy files back and forth to my Xyboard
Good day all, first of all, what am trying to do is have an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.