Portal Home > Knowledgebase > Articles Database > apply function for text box added through javascript


apply function for text box added through javascript




Posted by BM136, 08-31-2009, 05:37 AM
Hi, I want to add row in a table via script, and the row contains a text box where I want to add an onblur function for it, here is my code: for the textbox added through HTML, the function performs well, but it doesn't perform for the textboxes added through javascript. *you can just copy and paste the above code for testing can anyone help me and tell me how can the function applied through javascript? I'll appreciate any help

Posted by Eoin_, 08-31-2009, 07:12 AM
Weird, I just can't get it to trigger. I tried using addEventListener as well, and nothing works for me. I'll have another go at lunch.

Posted by mattle, 08-31-2009, 07:09 PM
Nasty little bugger, huh? Here's what got it: Problem is "checkQty(this)" is just interpreted as a string, not a function reference. However, checkQty(this) (without quotes) does reference the function, but interprets "this" in it's current context, which happens to be the windowObject. Lastly, checkQty(qty) works once! For some reason it fires at the moment of assignment, but then qty goes out of scope and you're basically calling checkQty(null) after that.

Posted by BM136, 09-01-2009, 06:31 AM
And what should I do to reference the function to be performed onblur?

Posted by mattle, 09-01-2009, 12:35 PM
Sorry...I forget that not everyone speaks in diff...it won't work if you try to set onblur() directly. Replace the top line with the bottom line and you should be set. (On FF anyway...that's all I tested).

Posted by BM136, 09-02-2009, 02:38 AM
Hi, thanks mattle for your time to help, I appreciate it . I tried something and it works, I should add it here to help anyone trying do the same, the following is the code we should replace qty.onblur = 'checkQty(this)'; in the previous code: here, the function will be performed onblur for each added text box.

Posted by siv9, 09-02-2009, 11:23 AM
Lookup "jquery Events/bind" on google. jQuery is one of the most amazing JavaScript tools I've ever come across. I'm particular once you get the hang of it you'll love it.



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
Apache (Views: 540)
ip ping Need Help (Views: 471)
WHM vs. HSphere. (Views: 504)
Tomcat Configure (Views: 446)