jQuery Submit with show/hide specific div and multiple forms not working as it should

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • skolbaek
    New Member
    • Mar 2021
    • 2

    jQuery Submit with show/hide specific div and multiple forms not working as it should

    Hello,

    I have a page with multiple users listed, and for each user multiple forms that should be able to be submited individual, with a response div that shows up on successfull submit and then disapear again af 10 sec. when I have a single form it works as it should, although you are only able to submit 1 time, but the big issues comes when I have multiple forms:

    Issues:

    1 : Even though I use let response_div = $(this).prev(); it always target the top DIV, and not the DIV above.
    2 : I am only able to submit 1 time, so if the user needs to correct something, they are not able before they reload the page again.
    3 : Field validation is also performed outside the form, i.e. the required is triggered in a different form than the one I submit.

    I have placed the code in a fiddle here: https://jsfiddle.net/skolbaek/2j4skwyr/2/

    I hope someone can help :-)

    /Stig :-)
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    The main issue would be that response_div is also an id and it's used multiple times. I also suspect that let may not be the right keyword for this use-case.

    Comment

    • skolbaek
      New Member
      • Mar 2021
      • 2

      #3
      I had my suspicions that one of the issues where the naming of the DIV, but how can I make that Dynamic in the jQuery? .. I can easily give the DIV a unique ID, but do not know how I can call it from the jQuery if it is unique.

      Any suggestions on the let case? :-)

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        I can easily give the DIV a unique ID, but do not know how I can call it from the jQuery if it is unique.
        Simply do not use ids when you don't need them.

        Any suggestions on the let case?
        If removing the ids doesn't help, try var.

        Comment

        Working...