Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Page submission on change of drop down value not working

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I came across a roadblock while developing my web app that uses JSP's .I use beans ,servlets and a JSP as view component. In my JSP , I have a form which has a dropdown as one of it's elements .The JSP also has a dynamically populated table that is populated on the basis of the selection in the drop down.
For this I have written the neccessary logic in my DAO layer , however Im confused as to how to reload the page based on the change in drop down value. As of now im using javascript.Somethign like this,



and the referencing html tag is


Am I doing something wrong?
Im a newbie and any help would be appreciated.
Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Submitting the form under script control is fine.

One suggestion I would make: stop using all uppercase for your html. That's so 1996.
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,
Thanks for replying.I am using JS , however the table does not refresh upon changing the value in the drop down , upon running the code in firefox , firebug pointed out an error on the
document.form.action="Main.jsp?DTobjid"; line
Why is this?
Please help
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I always use document.getElementById() to address elements. It's a lot less fragile than the old-fashioned methods.
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im sorry , but i didnt get what you meant.
I am using document.getElementById and its working fine too.
document.getElementById('selectedval').value=DTobjid;
However the error i face is at--

document.form.action="Main.jsp?DTobjid";
any pointers?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vic Hood wrote:I am using document.getElementById ...


But not here:
document.form.action="Main.jsp?DTobjid";

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im sorry i didnt quite get what you meant in the above post :s
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
document.form bad. document.getElementById() good.
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again,Bear.
I really dont get what you mean?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use document.getElementById() to fetch references to elements. Always.
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once again.
I am ]using document.getElementById()
In the lines.

what I m trying to figure out here
is how to submit to the form in the lines..

Hope you understand .
EDIT:Human error
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't care about the other lines. "document.form" is a loser! Use document.getElementById() to get the reference to the form element.

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the advice!works fine now. Here's the new snippet

where the form had an id='Main'
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Though I'd suggest a better name than "Main".
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Point taken!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic