jquery - Traverse DOM over and down -


I have a radio button group in a device, which has a cybill divis which has different text boxes, level 4 . If the radio button 'false' is checked, then I have to check all the text boxes in that group and if there is a value in a text box, then pop up a warning.

Now it pops up two alerts, regardless of the values ​​in the text box, any 'incorrect' radio buttons I'm not sure why the warning for any 'false' radio button is doubly, But I am pretty sure that it is not really reading the text box.

I agree that the search () method will show below many levels of children.

Edit - I should also mention that there are 5 questions, so the entire 'question' class is repeated 5 times and when the submit button is clicked, then it will have to check every question . / P>

Here's the markup:

  & lt; Div class = "question" & gt; & Lt; Div class = "radio-button" & gt; & Lt; Input type = "radio" name = "radio" value = "true" /> Yes & lt; Input type = "radio" name = "radio" value = "wrong" /> No & lt; / Div & gt; & Lt; Div class = "label" & gt; Date, name and listed out; Category .... & Lt; / Div & gt; & Lt; Div class = "north-container" & gt; & Lt; Fieldet class = "north-container-sub" & gt; & Lt; Div class = "north-group" & gt; & Lt; Div class = "question-label" & gt; Name & lt; / Div & gt; & Lt; Div class = "question-answer" & gt; & Lt; Input type = "text" / & gt; & Lt; / Div & gt; & Lt; Div class = "question-label" & gt; Name & lt; / Div & gt; & Lt; Div class = "question-answer" & gt; & Lt; Input type = "text" / & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "north-group" & gt; & Lt; Div class = "question-label" & gt; Name & lt; / Div & gt; & Lt; Div class = "question-answer" & gt; & Lt; Input type = "text" / & gt; & Lt; / Div & gt; & Lt; Div class = "question-label" & gt; Name & lt; / Div & gt; & Lt; Div class = "question-answer" & gt; & Lt; Input type = "text" / & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Fieldset & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Input type = "submit" id = "button" value = "click me" />   

jQuery ## The code below has been edited to change the name of the square, so it matches the html given above. ("(Click on button", "function") ($ ('input: radio'). (Each (function () {if ($ (this) .closest ('. Radio-button'). ('Input: Check '). Val () == "false" (if ($ (this) .siblings (' north-container ').' Input [type = text] '). Val ()! =' ') { Warning ("You did not click but there is a value in a text box");}}}};});

Some running issues may need to be done with the fact that a leading web of your HTML radio values ​​like "true" I need to remove that location.

I took a different approach (because some of your markup in your jQuery code is missing from this post) and it has been made that shows how easy it is to be DOM.

  $ ('input [name = "radios"]'). Change (function () {var currentValue = $ (this) .val (); // of spaces Required HTML can be removed from the radio values ​​if ('false' == current value) {var reply = $ (this) .clostest ('question') ('North-Container Q.'); $ (North) .Find ('Input'). Each (function () {var answerValue = $ (this) .val (); if (''! = AnswerValue) {warning (answerValue);}});}});    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -