• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Jsp code in javascript function

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! What's wrong with this function? It doesn't display anything in <div id="index"><div> tag. The problem is with that <select>.. I've done something similar, but instead of a <select>, i've had <input> and it worked.... Help, please! Thank you!

 
Sheriff
Posts: 6959
1317
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JSP rendered output of your code will be something like this:

Got it?
BTW, you must avoid using these Scriptlets in your JSP.
 
denisa Zivy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Devaka Cooray wrote:
Got it?


no... i know what the rendered output should be like, i wrote the function, didn't i? but the fact is that it doesn't work..

Devaka Cooray wrote:
BTW, you must avoid using these Scriptlets in your JSP.


I have to, i what a drop-down list to appear in <div id='index'></div> when a certain radio button is checked...
 
Marshal
Posts: 27372
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, you know what the HTML looks like. And now you have a question about why that HTML doesn't behave the way you think it should? Then you have a question about HTML and Javascript. It just happens that we have a forum dealing specifically with HTML and Javascript, so I'm going to move the post over there. It might help if you posted the actual HTML you have a question about, rather than obscuring it by posting some JSP code which is supposed to generate it.
 
denisa Zivy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, i will try to be more specific. So, i have a html form, and i want a drop-down list to appear when a radio button is checked or an input text if another radio button is checked.



changeToIsi() works just fine, but the second function not. and i can't figure out why.

Paul Clapham wrote:so I'm going to move the post over there.


ok, thanks, but i thought the jsp code is the problem here...
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wouldn't it make sense to post the rendered HTML that's causing the issue? We don't know what's in your variables.
 
denisa Zivy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After some minor changes from the previous version of the function:


Thank you for your time trying to get me out of this mess.

Note: i have other javascript functions and they've worked until i've written this function. Now they don't...
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is the worst way in the world to add options to a select element. Plus you are doing in 250 times? Major WTF there in my book.

You should never write to the document with innerHTML over and over again. You should build up the entire string and than set the innerHTML.

When you write the select tag to the page and set the innerHTML. The browser says, this forgetful developer forgot to close the tag, I will do it for them.

So you code will look like this



Why don't you just have a select element on the page with all of these options to start and just show it? Css display: none and inline will be your friend.

Eric
 
denisa Zivy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you very much for your advice. i know that 250 of options is a lot... but if my database is that large..
i will try to put all the select in a string, to see if that works.
again thanks
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

denisa Zivy wrote:thank you very much for your advice. i know that 250 of options is a lot... but if my database is that large..
i will try to put all the select in a string, to see if that works.
again thanks



Why is JavaScript doing this and not your server? It makes no sense. Have the server generate the string. I think you are really over thinking this.

Eric
 
denisa Zivy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:

denisa Zivy wrote:thank you very much for your advice. i know that 250 of options is a lot... but if my database is that large..
i will try to put all the select in a string, to see if that works.
again thanks



Why is JavaScript doing this and not your server? It makes no sense. Have the server generate the string. I think you are really over thinking this.

Eric



yes, in jsp code i ment. and then the function will look like this:


right?
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

denisa Zivy wrote:
right?



Probably not if you are asking that.

Are you escaping the double quotes?

Eric

 
Sheriff
Posts: 67671
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
Eric's point was: why are you generating JavaScript code to, in turn, generate the options when you could just generate the options in the JSP and lose the script completely?
 
denisa Zivy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Eric's point was: why are you generating JavaScript code to, in turn, generate the options when you could just generate the options in the JSP and lose the script completely?



because i was trying to display this drop-down list only if the user checked a certain radio button. I have 2 options, the user can choose to input something in an input text or to select something from that list.





still not working...
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then why not use the hide/show thing suggested earlier? Sooooo much easier than the mess you're working with now!
 
denisa Zivy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:Then why not use the hide/show thing suggested earlier? Sooooo much easier than the mess you're working with now!



yeah, i think you're right.... :D
if i've have had more experience i would have thought of that a long time ago :))
i'll give it a try
thanks:)
 
denisa Zivy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah, it works with show/hide, but still, i don't like the empty space of the hidden elements. i'm pretentious
 
Bear Bibeault
Sheriff
Posts: 67671
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
The show and hide technique should not result in any different-looking UI than before.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

denisa Zivy wrote:yeah, it works with show/hide, but still, i don't like the empty space of the hidden elements. i'm pretentious



You should not be using visibility. Re-read part of my previous post.


Eric Pascarello wrote:

Why don't you just have a select element on the page with all of these options to start and just show it? Css display: none and inline will be your friend.

Eric



Display does not maintain space. CSS 101.

Eric
 
denisa Zivy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great advices everybody. Thanks!
 
Hey cool! They got a blimp! But I have a tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic