0

I had the html like below

<input id="id_wow" placeholder="0.0" type="text" name="{{state.0}}" value="{{tax_value}}" class="must_be_float">
<br><span class="id_wow">hrray</span>

so when a user enters a value in input field other than float, i should fill this span text with "It must be float", but my jquery code is not working

jquery code

  $('.must_be_float').focusout(function() {
       var class =  $('.must_be_float').attr('id');
       var value = $('.must_be_float').val();
       if (value)
         {
          float_or_not = parseFloat(value);
          if(isNaN(float_or_not))
             {
              $('span.class').html('Value must be float');
             }
         }  
  });  

6 Answers 6

2

Try this

$('span[class="id_wow"]').html('Value must be float');
Sign up to request clarification or add additional context in comments.

Comments

1

Try this..

here i had made some changes in your code. now it work's fine.

HTML

<input id="id_wow" placeholder="0.0" type="text" name="{{state.0}}" value="{{tax_value}}" class="must_be_float">
<br><span Id="Msg" class="id_wow">hrray</span>

JQ

$("#id_wow").blur(function(event) {

      // var class =  $('.must_be_float').attr('id'); no need
     var value = $("#id_wow").val();     
     if( (value == +value) && (value != (value/0)) && (!isNaN(value)))
     {
         $("#Msg").text("Good It is Float a value");
     }
     else
     {
        $("#Msg").text("Value must be float");
     }

  });

Click Here For Live Demo

Also if u need textbox that accept only Float value:

Check this Click Here

If this is what you need put a Reply..

Comments

0
$('span.id_wow').html('Value must be float');


or

$('span.'+class).html('Value must be float');

In Jquery, the selector for a class is "."
Check it out Jquery Class

1 Comment

Please add some explanation to your post.
0

You are using wrong name for class in selector.

$('.id_wow').html('Value must be float');

3 Comments

the span has a class the selector should use a . not #
Thanks @MarkWalters, confucing class name, updated my answer.
No worries, I agree the example was confusing though.
0
$('span.id_wow').html('Value must be float');
//^^^^span then its classnme with "."

REFERENCE html()

Comments

0

I would do like this:

$('span.'+class).html('Value must be float');

But I did not test it.

Comments

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.