JQuery Default Form Values Advice

Soldato
Joined
8 Oct 2005
Posts
4,184
Location
Midlands, UK
JQuery .clone() help

Hi,

A quick JQuery help thread, this is nothing major, but would be nice to have :)

I'm using clone() to append new form fields to a form like this:

Code:
$('#orders').append($('#orders tr:last').clone(true));
This adds another field as expected, but keeps the values from the previous input - I can't seem to get the new inputs blank :( Have tried chaing the .val(" ") function too, with no luck. Any ideas?
 
Last edited:
For those interested, I just randomly figured this out weeks later :)

I decided to try the slightly less elegant .append:

Code:
$('table#orders').append(<tr><td>content</td></tr>);

Now I tried this before but it didn't work as I had spaces with the html I wanted to append (to make it easier for me to read) E.g.

Code:
$('table#orders').append(<tr>
<td>content</td>
</tr>);

Removing these spaces and appending the html as a single line worked. Now all the inputs within my appended html are blank (what I wanted) and not duplicated from the previous row.


Resetting the form would clear all values though, which could get annoying if you're half way through the fields when you add a new one.

I think the problem may be because you're duplicating the entire table row, and not acessing the value of the input directly - try this:

Code:
$("INPUT", "#orders tr:last").attr("value", "")
$("SELECT", "#orders tr:last").attr("value", "") // the value here should be the value of your 'Please select...' option

Must be the way I have this coded but that doesn't work :(

Off topic, have you got a link to way you've used the JQuery selectors there, as I haven't seen thasty before :)
 
Back
Top Bottom