• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp if in jquery code for dropdown select management

 
alit bizz
Greenhorn
Posts: 4
jQuery Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a form for a product who can have or not have some categories. The product is given by a web server so I'm using jsp to retrieve it. The product has a code and a version. The version can be associated with a category or not. If the product has more than one category, the user has to choose one from a dropdown menu of categories. Changing the category will also change the version sent in the form. If the product has no category, then the version of the product is sent to form without selecting the category.

Let's say, for example, that I have product A with code A01 this map of category and versions: {"large": "VL", "medium": "VM", "small": "VS"} and product B with code B01 and version VB.

In my code, I'm checking if the product has a map of category and versions bigger than 1 to choose if showing the select or not. This is done via jsp like this:



Then I'm using jQuery to manage the setting of the product version, like this :



But I'm wondering, is it ok to put a jsp if into jQuery code? Is there any other way I could be doing this? It works and all but I'm afraid my logic is bad.

I was also thinking of transforming the category and versions map into a json object and only work with jQuery, but the select html would be still generated in JSP and I don't know if that's ok (I've tried this way too but it didn't work).

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
alit bizz wrote:But I'm wondering, is it ok to put a jsp if into jQuery code?

No. You have a fundamental misunderstand about how JSP works. The JSP will execute on the server before the page is even sent to the browser. Please read this article to understand why this could never work.

Your conditional statement must be made via JavaScript, not JSP. If it needs values from the JSP, create JavaScript variables that contain the values.
 
alit bizz
Greenhorn
Posts: 4
jQuery Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your answer.
I've decided to append the input text only via JSP and to manage the dropdown menu change in jquery but using a javascript variable converted from JSP.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!