0

Example: dev.alphenweer.nl

When someone clicks on a link, the form gets loaded, they fill out the form, and press a button to submit it. But when someone presses the button, nothing happends. Why is that? What is wrong with my code?

For example, click on "REQUEST API AGAIN", and then just fill SOMETHING in. Nothing happens. Why?

1
  • @BillyMoon Its a bit of a code to post here. I setted up an example for you guys to watch and you can view the source freely. Commented Sep 27, 2011 at 21:27

2 Answers 2

1

You need to use live. Which will result in

$('#api_reg_submit').live('click', function(){... 

This happens because the button, which you set click event on, is not in DOM at start aka when its ready, but its added later. If you had the button outside and loaded only inputs it would work like you have it now. Hope it makes sense :)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! That worked out for me so well. I still don't realy understand why, but i'll think about it once again and hope that it makes sence for me then.. !
$(document).ready as its name suggests will handle everything that is inside it when the DOM is ready. Any element that will be added later via ajax or js, wont have any of these events you binded before. This means you will have to bind that event again. Easiest way of course is to duplicate your code, there are other methods as well, but I cant recall any in particular :/ And live in jquery will handle this for you.
0

There's no <form> surrounding the input elements, so they're just a random textbox and button sitting on a webpage. There's no element with an id of api_req_submit on the page either, so the click function you're trying to add has nowhere to go.

1 Comment

the api_req_submit gets loaded while loading the page. if you viewed the code, you can see that the href of a link gets loaded into the #content div, if you view the source of dev.alphenweer.nl/html/api_req_form.html you can clearly see that api_req_submit is on the page. And btw, why should there be a form tag? It isn't a form tag tho, just an ajax call.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.