0

So I have a textfield in a JSP page. When you launch the page, the textfield consists the text "Enter Account Name." Right now, the value of the textfield is "Enter Account Name."

What I want is...
"Enter Account Name" to be rewritten but I want no value in the textfield. This is the code I have so far.

<s:textfield name="searchBean.keyword"  size="25" id="inpKeyword" title="Enter Account Name"   style="color:#888;" value="Enter Account Name" onfocus="if(this.value=='Enter Account Name') this.value='';" onblur="inputBlur(this)"/></li>
Roman C
  • 49,761
  • 33
  • 66
  • 176
user3123222
  • 1,185
  • 2
  • 10
  • 13
  • https://www.google.com/search?q=html5+placeholder+attribute – CBroe Feb 25 '14 at 15:27
  • possible duplicate of [How can I put a placeholder in a struts textfield tag?](http://stackoverflow.com/questions/20209487/how-can-i-put-a-placeholder-in-a-struts-textfield-tag) – Luiggi Mendoza Feb 25 '14 at 15:30

2 Answers2

1

Can you try using the placeholder attribute?

<s:textfield name="searchBean.keyword"  size="25" id="inpKeyword" title="Enter Account Name"   style="color:#888;" placeholder="Enter Account Name" onfocus="if(this.value=='Enter Account Name') this.value='';" onblur="inputBlur(this)"/></li>

The placeholder attribute only gets applied when the field is blank, so I've also removed the default value attribute.

andygeers
  • 6,909
  • 9
  • 49
  • 63
  • -1: The problem is that `` doesn't allow having `placeholder` attribute: http://struts.apache.org/release/2.1.x/docs/textfield.html – Luiggi Mendoza Feb 25 '14 at 15:30
  • 3
    @LuiggiMendoza: `` tag allows dynamic attributes. – Aleksandr M Feb 26 '14 at 09:39
  • @LuiggiMendoza Seems that you link to the deprecated version of Struts the docs page is no longer updated, but even there you should better read it if you work with it. – Roman C Feb 26 '14 at 21:51
  • @RomanC we already have a similar discussion related to JSF. If you have an answer, post it instead. It is not my fault that this technology has an outdated documentation... Also, OP should have posted this question belong to struts to begin with... – Luiggi Mendoza Feb 26 '14 at 22:15
  • 2
    @LuiggiMendoza This post *isn't* related to JSF. Regarding the documentation it's *up to date*, I don't know where did you get that link. Also it does change nothing if they begin struts or not they post to the tag. – Roman C Feb 27 '14 at 08:48
0

This is done by

<input ..........    placeholder="Enter your amount" ......./>
Ashish Ratan
  • 2,838
  • 1
  • 24
  • 50