• Post Reply Bookmark Topic Watch Topic
  • New Topic

Text box value attribute & javascript expressions

 
Reed Peters
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a problem with the Text Box's value= attribute and the usage of a javascript expression to prime it. Here's a sample JSP that illustrates the problem:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META name="GENERATOR" content="IBM WebSphere Studio">
<TITLE>testJSP.jsp</TITLE>
</HEAD>
<BODY>
<% String stringField = "Hello There!"; %>
<%=stringField%>
Input Text Box:<INPUT size="30" type="text" maxlength="30" name="aField" value=<%=stringField%>>
</BODY>
</HTML>
Notice that the stringField is set to "Hello There!" and that it is used to prime the value in the Text box using a javascript expression. However, only "Hello" shows up in the text box.
Does this work differently for anyone else? Is there anyway to dynamically prime the text box's value with the complete string with imbedded spaces?
HELP!
 
Alfonso Harding
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using this:

putting the single quotes around the value='<%=stringField%>' prints the whole string.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few things:
1) Always get in the habit of quoting your tag attributes -- just because HTML let's you get away with it most of the time, you've experienced the pain that can ensue...
2) When you are running into problems like this, generally using the browser to view the HTML source that is interpreting helps to identify what's going on.
3) <%=stringField%> is NOT a javascript expression, it's a JSP scriptin expression. Big difference.
hth,
bear
[ September 25, 2002: Message edited by: Bear Bibeault ]
 
Reed Peters
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
YEA!
Thank you Alfonso the single quotes fixed it!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!