• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

How to add a value to a dynamically created input field in a dynamically created table?

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am dynamically creating a table containing an <input> (the one marked as "//Award". How do I populate it with a value using its name (name='awardInput').

My code is:






The "alert(responseJson1a['awards']);" displays "Animals and Birds - Level 1, Art and Design - Level 1".

Then "selector.closest('tr').find('.awardClass').$('input[name="awardInput"]').val(responseJson1a['awards']);" gives the console error "Uncaught TypeError: selector.closest(...).find(...).$ is not a function".

Kind regards,

Glyn


Capture.PNG
Page
Page
 
Marshal
Posts: 26135
77
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To provide an HTML "input" element with a value, you assign something to its "value" attribute. Right now you don't have one on the line you referenced, but you could certainly add one and put a bit more string concatenation in your code to populate it. (I don't understand what you mean by "using its name".)



 
Glyndwr Bartlett
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

By using its name I mean instead of its id:



Instead of:




I am not sure what you mean. I am trying to use:



To assign the value to:



Kind regards,

Glyn
 
Marshal
Posts: 67478
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the final generated HTML structure that you are trying to search (not the source that creates it).
 
Glyndwr Bartlett
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

The final html is:



Kind regards,

Glyn
 
Glyndwr Bartlett
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I use:



Then this input field on all rows is update. So I need to bee able to identify just the row on which I am selecting the option on.

Kind regards,

Glyn
 
Bear Bibeault
Marshal
Posts: 67478
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the target is inside a table row, using .closest('tr') should set the context.
 
Glyndwr Bartlett
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

I tried:



And this throws a console error "selector.closest(...).$ is not a function".
 
Glyndwr Bartlett
Ranch Hand
Posts: 100
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear,

The answer is:



Kind regards,

Glyn
 
Bear Bibeault
Marshal
Posts: 67478
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, .find() is what you need to search within a context.
 
That's a very big dog. I think I want to go home now and hug this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic