Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Dynamically setting the name of an input text control in jsp using EL  RSS feed

 
Ranch Hand
Posts: 59
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Can someone please let me know, how to set the name of an input checkbox control dynamically?

Part of the name, will include the product code procured via EL from the session scope attribute.

Let us assume the product code is "8601".

Now I want to have a checkbox with the name 8601_check and want to set this dynamically in my jsp page.

How do I do the above?

Right now, all I have is the following:



I get an error message saying, "Invalid location of text(+") in tag(<input>).
 
Marshal
Posts: 67164
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that everything outside of JSP elements is just template text, so:
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also remember that even if you automatically generate them, they should still be valid names.

8601_check is invalid as it starts with a number rather than a letter or underscore character.

I would suggest "check_8601" instead just to avoid the problems :-)

 
Bear Bibeault
Marshal
Posts: 67164
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, id values that start with numerics are completely valid. Whether they are a good idea or not is another matter...
 
Ravi Desigan
Ranch Hand
Posts: 59
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for the replies! Appreciate it, my problem is solved now.
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Actually, id values that start with numerics are completely valid. Whether they are a good idea or not is another matter...



I guess I'm out of date.
Reference to the HTML 4 spec

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").



It got changed in the HTML5 spec to be more permissive



 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!