![]() |
Cannot Find Error in JQuery
Could someone help me? I need to find my error. I'm nearly about to pull every hair out of my body. I'm trying to make a todo list web app with Javascript and not PHP. It nearly works, but I can't get this for loop to work. Could someone also help me get it working because I'm so close. Here's the source:
Javascript/JQuery Code:
$(document).ready(function() {Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
Another option without using jquery.
When you click the "Add items" button, the textboxes that you added with the "+" button are moved to the addedItems div.Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
Code:
var idCounter=1; |
Quote:
idCounter is being incremented as well on each loop iteration and so i will always be < idCounter.But imo for something relatively basic, it's easier without jquery. |
Am I missing something then - how is idCounter anything other than 1 within $("#addButton").click function?
|
yep, I think you're right. I didn't notice where it was being initialised and so assumed it was initially 0.
|
Quote:
|
Try this :)
Code:
function addItemsToForm(){ |
Quote:
If you want to copy them, then all you need to do is clone the original inputs and append them to the appropriate element in the form. In this case the while loop would need to be a for loop and you'll need a couple of other minor tweaks as well. If you want to copy just the values of the original inputs you can get them from the inputs value property. You will also need to delete any existing contents in 'addedItems' before appending any new items otherwise you will get duplicate data if you create new items after already adding some. |
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
I quite like
Code:
var addedBefore = document.getElementById('addedItems'); |
yep, that's even more efficient :thumbsup:
If I remembered firstChild I would have used it myself :) |
See below.
|
Quote:
|
Use createElement() to create new inputs and set the 'value' of these inputs to the 'value' of the ones whose text you want to copy.
|
| All times are GMT +1. The time now is 03:48 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.