Okay I have a jQuery dialog box which has a form in it and I am at my wits end trying to figure this out... Lets see if I can verbalize what I am trying to do..
I have 3 text boxes. #apInterest
, #apPayment
and #apPrincipal
in that exact order.
basic english terms of what i am trying to do:
on keyup in #apInterest
if .val
is less than 0 or greater than 99.99 trigger an error.. else check ul#mylist
if it has any li
, if not .hide
on keyup in #apPayment
if .val
is less than 0 trigger an error else check the list for li
hide if not.
#apPrincipal
is the same thing exactly as #apPayment
what I have right this moment
$('#apInterest').live("keyup", function(e) { var parent = $('.inter').parents("ul:first"); if ($('#apInterest').val() < 0 || $('#apInterest').val() > 99.99) { $('.inter').remove(); $('#mylist').append('<li class="inter">Interest Rate cannot be below 0 or above 99.99</li>'); $('#popuperrors').show(); $(this).addClass('error'); } else { $(this).removeClass('error'); $('.inter').remove(); alert(parent.children().text); if (parent.children().length == 0){ $('#popuperrors').hide(); } } });
Although I have also tried
if ($("#mylist :not(:contains(li))") ){ $('#popuperrors').hide(); }
I had a function similar to this for all 3 textboxes but none of what I have tried seems to work.. any ideas on how to complete this
if(data && data != "") alert(data); data will be null in your case, and null != "" , so the if is passing.
The empty() method removes all child nodes and content from the selected elements. Note: This method does not remove the element itself, or its attributes. Tip: To remove the elements without removing data and events, use the detach() method.
Each of the list elements of the unordered list is first selected using a jQuery selector. The each() method is used on this list to iterate through it. This method has a callback function that returns the current index and the element of the iteration.
Use the childNodes property to check if a div element is empty. The childNodes property returns a NodeList of the element's child nodes, including elements, text nodes and comments. If the property returns a value of 0 , then the div is empty.
if ($('#mylist li').length == 0) ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With