Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Ravi Desigan
Ranch Hand
Posts: 32
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>).
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65661
129
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:
 
Stefan Evans
Bartender
Posts: 1826
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
Author and ninkuma
Marshal
Posts: 65661
129
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: 32
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: 1826
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



 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!