This week's book giveaways are in the Angular and TypeScript and Web Services forums.
We're giving away four copies each of Programming with Types and The Design of Web APIs and have the authors on-line!
See this thread and this one for details.
Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Joe Ess
  • salvin francis

JQuery.UI Dialog & $().load() & JavaScript

Ranch Hand
Posts: 15304
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On an event I am showing a JQuery.UI dialog. The way JQuery.UI Dialog works is it expects an existing DIV to simply transform into the dialog. I need a form in the dialog but I need it populated and shown via ajax. So here is how I go about doing that.

Note that the following line...

...takes the DIV element I created and performs an AJAX request to get the desired HTML. That HTML looks like...

This works. Note that now I have a script being loaded for this html. This code is where the problem eventually occurs. The first time I show the dialog everything works. There is a text field and a button. I enter something in the text field and hit enter or click the button and that value is submited via AJAX to the server and a table in the dialog is updated. However, subsequent times showing the dialog part of the script isn't working but no errors are being thrown.

The saveSynonym() function is always called. if I alert the lengh of $('#synonym\\.name') it is always 1 so I know it is only finding one element. However, $('#synonym\\.name').val() is coming back empty. Normally, that would trigger the error portion of the code. But the error isn't showing up either.

Just to reiterate, the first time the dialog is shown everything works as expected. Subsequent times it does not.
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!