using jquery on checking duplicate data |
[eluser]clariz[/eluser]
Could anyone help me on this? I have dynamic textfields, generated using innerhtml I want that onblur event, the data in the textfield will be checked for duplicate in the database. The checking will be done without refreshing the page. Then give an alert if duplicate exists. I have a code using jquery. I've tried it using static textbox. It works fine. But when I applied the dynamic textboxes, it doesn't works. Here's my code: I have a javascript code and two forms in my html code. The code goes like this, when I enter a value in my textfield id = Que and on onblur event, the next textfield id = textQuestion gets the value of the textfield id = Que and the form id=formCheck submits the form. The data is process to a php file, checking if the value exists in the database. Then returns a value. Code: < script type="text/javascript"> This is my controller: It checks the value in the database Code: <?php And this is the code to generate dynamic textboxes Code: var arrInput = new Array(0);
[eluser]Jay Turley[/eluser]
If I am not mistaken, you have run into the dreaded binding problem. ;-) Because you bind your jquery event handlers to the static textboxes when the document is ready, you do not experience a problem. But the binding is only done once - at page load / DOM ready. You need to do one of two things: read up on jQuery event handling (it looks something like this): Code: var that = this; or you need to rerun your document ready function each time you add a new dynamic input to the DOM. HTH
[eluser]clariz[/eluser]
Quote:If I am not mistaken, you have run into the dreaded binding problem. ;-) Thanks for the reply Jay Turley. Now I got an idea about the problem. Quote:You need to do one of two things: read up on jQuery event handling (it looks something like this): But I am new to jquery. Could you help me understand the code you have given? I wish you could elaborate it to be clear to me... And how could I return the document ready function each time? Thanks in advance. Your reply is very much appreciated. -clariz-
[eluser]Jay Turley[/eluser]
[quote author="clariz" date="1221641773"] Thanks for the reply Jay Turley. Now I got an idea about the problem. But I am new to jquery. Could you help me understand the code you have given? I wish you could elaborate it to be clear to me... And how could I return the document ready function each time? [/quote] No worries. First, here is a link to a great introductory page on event handling and event delegation in jquery. For your case, I would read the page and then look carefully at Example 2. event delegation with jquery As far as rerunning the event binding, it would look something like this (please note this is example code, you will have to change it for your needs) Code: $(document).ready( function() {
[eluser]clariz[/eluser]
Thanks a lot Jay Turley.. I'll try that code.. I'll just post for any changes. :-) -clariz-
[eluser]clariz[/eluser]
Thanks Jay Turley for giving new ideas. I came up to a code which solved the problem. I also used your code as a reference. At the end, the code I made was not that good but it solved the problem which is more important (to have an output) :lol: JS code in a separate file: Code: function clickHandlers(e){ Same html code except this line Code: Question <input type='text' name='Que[]' id='Que' size='38' /> I changed it to Code: Question < input type='text' name='Que[]' id='Que' And also in creating dynamic textfields was changed to Code: Question <input name='Que[]' type='text' class='inputQuestion' id='Que' I just added a call to a function. I hope anyone could find this post useful. Thanks for the persons who read this post especially to Jay Turley for all the replies. ;-) -clariz- |
Welcome Guest, Not a member yet? Register Sign In |