1

I have shown on the link what I need, for some reason the adding is not working but on my page is it, but thats not the problem. The problem is once I have added a new row, the new row drop down box does not work when selecting volvo, the textbox does not appear.

Will_S
  • 71
  • 1
  • 11

1 Answers1

2

Because after adding the new row you are not updating the id and name fields of the new element. After you create new elements update there ids before appending them.

Since you are creating the dom elements dynamically use delegate or on to attach event handlers.

    $('form[name=form]')
    .delegate('#car', 'change', function() {
        var val = $(this).val();
        $('#hdn_sel').val(val);
        $('label').hide();
        showLabels(val);
    })
    .delegate('input', 'focus', function () {
        $(this).next("span").fadeIn(1000);
    })
    .delegate('input', 'blur', function () {
        $(this).next("span").fadeOut(1000);
    });

I have fixed your fiddle and also modified the code as you wanted take a look.

http://jsfiddle.net/ShankarSangoli/PEYFc/3/

ShankarSangoli
  • 67,648
  • 11
  • 84
  • 121
  • 1
    Use the latest jQuery because the code uses `on` which is added in jQuery 1.7. Here it is http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js – ShankarSangoli Feb 13 '12 at 00:10
  • If its hidden then don't validate it. You can check if the element is hidden using `$('elementSelector').is(':hidden')`. Mark this as answer if you are satisfied with it. – ShankarSangoli Feb 13 '12 at 19:11
  • I have looked at this - http://stackoverflow.com/questions/178325/how-do-you-test-if-something-is-hidden-with-jquery, which looks like what u said but does not work. I have got it here - http://jsfiddle.net/PEYFc/10/ – Will_S Feb 13 '12 at 22:28
  • The selector is wrong in your fiddle, you have missed `#` in it. Try this `$('#car').is(':visible')`. – ShankarSangoli Feb 13 '12 at 22:29
  • While validating you should loop through each row in the table and execute the validation log for elements inside each loop. – ShankarSangoli Feb 13 '12 at 22:40