• 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

How do I resolve this? Adding loop item to a list

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


When I click on the submit button, the specified item shoud be added to the item-list/cart. However, I am not getting the result I am expecting.
What is happening is that when the page have loaded, the "onclick" function have executed on all the items in the loop.

How do I resolve this?
What options do I have besides "onclick", which seems buggy?
 
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

Pojahn Moradi wrote:What options do I have besides "onclick", which seems buggy?


onclick is not buggy; your code is.

You are mixing server-side code with client-side code; and the two cannot be mixed. Please read this article to understand how JSP operates and why what you are trying to do makes no sense.

You need to deal with client-side actions such as button clicks with JavaScript on the client; not JSP on the server.
 
Pojahn Moradi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right. It makes more sense now. Sill clueless on how to resolve this issue.
 
Bear Bibeault
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
First item of advice: ditch the Java scriptlets. They've been obsolete for over 12 years and should no longer be used on JSP pages. Learn to use the JSTL and EL instead. See this JspFaq entry.

Advice #2: with your new knowledge of how JSP works, you'll need to sit back and rethink your approach. Your original approach assumed that you'd be able to add to the list in real time as buttons are clicked. Not so. To make any changes to the server, you need to go back with a new request -- either a link, a form or an Ajax request.

All of that requires a major refactor from the start. So don't try to band-aid what you've got; it's just going to lead to frustration. Sit back and think about how you can approach this knowing that once the JSP executes and sends the HTML to ther browser that you've got to wait for a new request to come back to do anything else.
 
what if we put solar panels on top of the semi truck trailer? That could power this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic