GeeCON Prague 2014*
The moose likes HTML, CSS and JavaScript and the fly likes access dynamically created textfield with jquery Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "access dynamically created textfield with jquery" Watch "access dynamically created textfield with jquery" New topic
Author

access dynamically created textfield with jquery

adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi all.

I am currently able to sum up values of given text field, and want to do the same by creating dynamic textfields and accessing them by their classnames. I have successfully created dynamic textfields. I have checked the code with firebug. All class names are correctly assigned as it was done manually. Now I am not getting the output when I am creating textfields dynamically. Is this possible or I have simply for so long??



Thanks and Regards
Adeeb.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61298
    
  66

"not getting the output" <-- what does this mean?

Please explain things more clearly.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Thanks for the reply Bear.


To be more clear when I am hand coding the elements like below



in the table and using jquery I am doing multiplication operation. This is fine. It is working if define in the code those elements. The problem is I am creating elements dynamically on clicking the button. The code is below




This is also fine the fields are created. But jquery is not working on it. NOTE: There is no mistake in assigning classes and id's as I have copied the code from fire bug, then pasted in the table and tested. But again the same code when generated by clicking the button I think jquery is unable to access it. How can that be, I am not sure and confused. My Jquery code is below.






Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61298
    
  66

Why aren't you using jQuery to create the elements?

And please fix up the wonky indentation. Makes the code really hard to read.

And, have you used the JavaScript console to inspect the DOM after the additions so you can see if the elements have been added as you expect?
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
So, you mean in order to access the elements with jquery I have to create elements with jquery only???
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61298
    
  66

Please show me where I said that.

No, I asked why you were doing things the hard way instead of the easy way.
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
K sorry I got you in wrong way. I will create with jquery later. First I want to know what the exact problem is, where I am going wrong. Also I am not good in jquery, and this type of bugs are scaring me. :d. I am struck here from almost 8 hrs. How can this be, the elements created have exactly same values as I wrote manually. Its working when written manually but not when auto generated.


Thanks Bear for spending your time looking into the problem.
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hey this could give a clear understanding of the problem. The code below contains both hardcoded(written in file) and auto generated code. The above is written manually. The second row is auto generated. Now only first row is giving the desired output. i.e if I enter value in 2nd and 3rd text field I am getting result in 4th textfield.



Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61298
    
  66

Did you follow my instructions regarding using the JavaScript console to inspect the DOM to see if the elements are created as intended?

If not, then you are wasting both our time.

And please indent your code and HTML. I will no longer look at unformatted code now that you've been asked twice.
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi Bear.
I dint understand what code format you are talking about. Please give a small example so that i wont do such mistakes again. The problem is solved and the code is below. Hope this will be useful for someone.



Thanks for the Help Bear.
 
jQuery in Action, 2nd edition
 
subject: access dynamically created textfield with jquery