Skip to content
Advertisement

adding dynamically input box but it should stop base on the criteria,,,

elow is the code i am using i am able to add new input box wen i click but it should stop adding based on the user input like no. of user-entered as 4 based on that add input box should stop

in below example:-$bookcount is user input field which comes from html input box

JavaScript

enter image description here

Advertisement

Answer

Couple of issues to note:

  • Assuming bookcount is found from $("#bookcount") then you’ll need to get the .val() and convert it to a number (as “10”<“2”)
  • Check against bookcount value inside the click event:
JavaScript
  • as you also have a remove function, don’t forget to reduce i when removing
JavaScript

(in this case, I recommend something other than i, eg rowCount).


You can also do away with i (rowCount) by querying how many rows have been created dynamically:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement