• 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

jquery dialog causes action

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To open any page on the web-site I use ToolbarAction.do where I check want button sent form and then .

To load this page book.jsp action ResponseAction.do is used. There is jquery dialog form. When I press button #request it should show form #dialog-form and when all fields are valid I send this form.

But when I press button to show form - it closes immediately. In debbuger I found out that opening #dialog-form causes ResponseAction.do again.

How to solve this problem?
 
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
That a bit too much code to wade through. Please post an SSCCE that shows the problem.

Edit: I just happened to notice this: onClick="" on your button. Don't know if that's causing any issues, but it certainly doesn't belong there.
 
James Whillis
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here I make it smaller. Javascript code - it's jquery dialog form. The problem is when I press button with id request - it show #dialog-form but then closes it immediately.
In debugger I found out that when I press button - event ResponseAction.do occurs - It is the same event that open this page. And I don't know how to solve this problem.
 
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
Any chance you could post an example without all the server-side markup? That all makes it impossible to load into a jsFiddle, or even a local file, and see what's going on.

Besides, the JavaScript "sees" what's sent to the browser, not the server-side code, and it's best to debug script issues (and CSS as well) by looking at what's sent to the browser.

The most likely thing that's going on is that the button press is not only triggering your script handler, but submitting the form. Just why is what is the question.
 
James Whillis
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Any chance you could post an example without all the server-side markup? That all makes it impossible to load into a jsFiddle, or even a local file, and see what's going on.

Besides, the JavaScript "sees" what's sent to the browser, not the server-side code, and it's best to debug script issues (and CSS as well) by looking at what's sent to the browser.

The most likely thing that's going on is that the button press is not only triggering your script handler, but submitting the form. Just why is what is the question.



I can't. The problem exactly with server-side because it causes by actions. On simple html page it works normal. To open this page I use action ResponseAction.do. But When I press button with id request it causes the same action. But should only open form. Maybe it refreshes page. I don't know.


To represent this problem it either needs something like TV or the whole project.
 
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
You can see what's actually being sent to the browser with a View Source or with the JavaScript debugger in the browser.

You can also set breakpoints in the JavaScript with the debugger.

My point is, trying to debug this on the server isn't going to make things very easy for you.

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another thought: you haven't put a type attribute on your button. Now, the default is supposed to be "button" which should not automatically submit the form, but it's not a bad practice to be explicit about it. There are some circumstances where a form will auto-submit implicitly (such as when there's one field and the user hits Enter).

Just to be safe, and complete, I'd go ahead and add type="button" to the button, even if it doesn't solve the problem.
 
James Whillis
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:You can see what's actually being sent to the browser with a View Source or with the JavaScript debugger in the browser.

You can also set breakpoints in the JavaScript with the debugger.

My point is, trying to debug this on the server isn't going to make things very easy for you.



How to do it in Chrome? I can't find where to set breakpoints.
 
James Whillis
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Another thought: you haven't put a type attribute on your button. Now, the default is supposed to be "button" which should not automatically submit the form, but it's not a bad practice to be explicit about it. There are some circumstances where a form will auto-submit implicitly (such as when there's one field and the user hits Enter).

Just to be safe, and complete, I'd go ahead and add type="button" to the button, even if it doesn't solve the problem.




Oh! It works when I set type="button"
 
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

James Whillis wrote:Oh! It works when I set type="button"



Aha. The browser is apparently defaulting the button to type submit.

This is why I'm always explicit and never omit the type attribute. I'll bet you'll be adding it to all buttons in the future as well!
 
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

James Whillis wrote:
How to do it in Chrome? I can't find where to set breakpoints.


You set breakpoints in the Sources tab. Here's a clickable screenshot with a breakpoint set (on line 10).



Click to see full-sized.

Breakpoints are set and cleared by clicking on line numbers.

(The example code is from a question that was asked here last week.)
 
James Whillis
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

James Whillis wrote:Oh! It works when I set type="button"



Aha. The browser is apparently defaulting the button to type submit.

This is why I'm always explicit and never omit the type attribute. I'll bet you'll be adding it to all buttons in the future as well! :cool:



However when I press button on dialog form it doesn't submit it.
 
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
Now's the time to put those debugging skills to work. Set a breakpoint in the handler. Does it get invoked? If so, step through the statements to see where it is going awry.
 
James Whillis
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Now's the time to put those debugging skills to work. Set a breakpoint in the handler. Does it get invoked? If so, step through the statements to see where it is going awry.



I've solved this problem. I simply submitted form with id of div tag
 
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic