Bit of a nooby question here. Basically, I'm adding inputs to a form after the DOM has already loaded. I want to run validations (basically, strip dollar signs and round the numbers) and a checker to make sure only 20 of these fields may be loaded. I know just enough to recognize that neither of these are possible the way I'm trying since everything is already loaded and the functions aren't going to act on the new elements. I don't know much more about the problem, nor how to fix it.
$(document).ready(function(){
//add up to 20 debts and assets
$("#before_debt").live('click', function(){ insertNode('primary[debt]', '#before_debt', $('#pri_debts').size('input') );})
$("#before_asset").live('click', function(){ insertNode('primary[addi]', '#before_asset', $('#pri_assets').size('input') );})
}
//messy insert element function...
function insertNode( name_prefix, button_id, counter ){
var i = $('input[name^=\''+ name_prefix +'\']').last().attr('name').substr(14, 1);
i = parseInt(i);
i++;
var is_debt = '';
if( name_prefix == 'primary[debt]' ){
is_debt = '<input type="hidden" name="primary[debt][' + i + '][is_debt]" value="1">';
}
if( counter <= 20 ){ //counter never increments
$(button_id).before('<tr><td>'+ is_debt +'<input type="text" name="'+ name_prefix +'[' + i + '][account_name]" size="20" maxlength="40"></td><td>$<input type="text" class="strip" name="'+ name_prefix +'[' + i + '][account_value]" size="20" maxlength="10"></td></tr>');
}
}
//strip the dollar sign from all 'strip' class elements
$('.strip').blur(function() {
$(this).val(function(index, val){
var stripped = val.replace('\$', '').trim();
return Math.round(stripped);
});
});

New Topic/Question
Reply



MultiQuote



|