• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Text box value attribute & javascript expressions

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using this:

putting the single quotes around the value='<%=stringField%>' prints the whole string.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
YEA!
Thank you Alfonso the single quotes fixed it!
 
reply
    Bookmark Topic Watch Topic
  • New Topic