1
var id = "<?php echo $val->id; ?>";

var myRadio = $('input[name=<?php echo "mala".$val->id; ?>]').val();

if (myRadio.val.length > 0){
   $("#anketa").load('http://www.svastara.rs/anketa/anketa_m1_data', 
       { answer: myRadio, id: id });
   }
});

Why this if (myRadio.val.length > 0) returns it looks like false, when i am sure that there is something in the string. If its not a good way, how to check that the string is empty or not?

1
  • It shouldn't "look false", it should (probably) throw an error. Why are you trying to take val of val()? Commented Oct 24, 2012 at 11:10

3 Answers 3

6

No need in val, since you should already get the value with val() method in the previous line:

if (myRadio.length > 0) { ... }
Sign up to request clarification or add additional context in comments.

1 Comment

still load the link, when i click on button and do not choose radio button
0
if(myRadio)
return true;
else
return false;

Comments

0

You don't need to use myRadio.val.length due to myRadio is already the value of that input. So all you need is to check this variable with length.

var id = "<?php echo $val->id; ?>";
var myRadio = $('input[name=<?php echo "mala".$val->id; ?>]').val();
if (myRadio.length > 0){
     $("#anketa").load('http://www.svastara.rs/anketa/anketa_m1_data', { answer: myRadio, id: id });
}

You can have a better explanation at http://www.w3schools.com/jsref/jsref_length_string.asp

Good luck!

1 Comment

I do not know why but it always give a true

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.