Skip to content
Advertisement

Adding datepicker in dynamically added inputs

I’m trying to modify a code I downloaded, the code permits to add/remove dynamically added inputs text and a dropdownlist, in file index.php I select an account name from dropdownlist ($row["name"] and fetch the account Id $row["account_id"]) and enter an amount in a input field (name="amount[]"), then an insert the data using insert.php in Mysql database.

Now I want to add/remove a input dynamically with a datepicker for selecting from the calendar (datepicker) the date in which the expense was made and if I have add several account expense to register the dates entered can be different for each item, Please Any ideas, I don’t know how to do it.

This is Index.php:

JavaScript

This My insert.php code for insert data entered:

JavaScript

In the index.php code I have the datepicker input field but isn’t part of the dynamically add/remove code:

JavaScript

Another question If I leave the datepicker input field out the of the dynamically add/remove code, but I want to select just one date in calendar, How can I pass the input date variable to insert.php?

Thanks in advance

Advertisement

Answer

You just need to append datepicker inputs like you are already doing for other inputs then after adding same inside your table you need to initialize it . So , you can simply use $('#item_table tr:last .datepicker').datepicker(options) this will find last tr added inside your table and inside that tr get .datepicker and initialize same

Demo Code :

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