• 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

Problem with javascript onChange and servlet

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application where I use jquery for the validation (I know almost nothing about jquery - just enough to get it into my web page and running, but little more). In this application I also had a need to have a drop down field whose options were dependant on the dropdown field above it. (So, when the department is chosen, the options for the request type change based on which department is selected.)

I added my own small javascript file/function to do the changing of the options in that second field (onchange) when the first field changes.

My problem is that when I attempt to submit the page, jquery complains that the field is required. So to test things, I made the field not required so jquery wouldn't complain, but my servlet also is not pulling the value from the field.

I'm assuming the problem is something to do with my javascript code that sets the field options, however, I don't know what is wrong. This is the only field where I'm having this problem and this is the only field where the options are set via javascript.

If I remove the onchange event and just set a single option for the field, everything works as expected, however, as soon as I add the onChange back into the picture, then jquery thinks the field is empty and my servlet does as well.

This is my javascript function:



And here's the relevant part of my servlet:


And this is my jsp (when the department field changes, onChange kicks off and sets the options in requesttype. I cannot seem to get jquery or my servlet to recognize that there is a value in requesttype when I submit):


Any ideas on where I've gone wrong? Thanks!
 
K DeLucia
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it. After much hair pulling, I discovered that these lines:

document.inquiryForm.requesttype.options[1] = new Option("Paybacks/deductions", "");

should look like this:

document.inquiryForm.requesttype.options[1] = new Option("Paybacks/deductions", "Paybacks/deductions");

Everything is working beautifully now.
 
This one time, at bandcamp, I had relations with a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic