1

I want to print an input type number on confirmation page.

var displayConfirm = function() {
            $('#tab5 .form-control-static', form).each(function(){
                var input = $('[name="'+$(this).attr("data-display")+'"]', form);
                if (input.is(":radio")) {
                    input = $('[name="'+$(this).attr("data-display")+'"]:checked', form);
                }
                if (input.is(":text") || input.is("textarea")) {
                    $(this).html(input.val());
                } else if (input.is("select")) {
                    $(this).html(input.find('option:selected').text());
                } else if (input.is(":radio") && input.is(":checked")) {
                    $(this).html(input.attr("data-title"));
                } 
            });
        }

If I use input.is(":number") and $(this).html(input.val()); it crashes.

4
  • 1) there is no input with the type of "number" in html. 2) show your html, this could clarify what you want to achieve. Commented Sep 15, 2015 at 8:49
  • there is <input type="number" name="quantity" min="1" max="5"> Commented Sep 15, 2015 at 8:50
  • 1
    @low_rents: surprise....w3.org/TR/html-markup/input.number.html :P Commented Sep 15, 2015 at 8:50
  • @MilindAnantwar ok, but it is maybe so new that his version of jQuery might not know about it :) Commented Sep 15, 2015 at 8:54

3 Answers 3

1

The reason it crashed because :number is not valid selector. You need to use attribute equals selector in .is() condition:

input.is("[type=number]")

Snippet:

else if (input.is("[type=number]")) {
    $(this).html(input.val());
} 
Sign up to request clarification or add additional context in comments.

6 Comments

BTW, Do I need to change :text to [type:text] ?
@ArasSerdaroğlu: nop.. jai already mentioned, its perfectly valid as jquery have selector :text for type text
one more question, I want to show a preview for input file (image) on confirmation page, how to do that?
You can show them in modal along with confirm button
I'm listing all my inputs in a single page.
|
1

For completeness, you can register a jQuery pseudo selector if you wanted to stick with :number:

$.expr[':'].number = function(el){
  var $el = $(el);
  return $el.prop('tagName').toLowerCase() == 'input' && $el.prop('type') == 'number';
}

.is(':number') would then work perfectly fine for you.

JSFiddle

Comments

0
$('#qwe').keyup(function () {
    alert($(this).val());

});

FIDDLE

To get value of input element use .val()

4 Comments

well @pekka i guess OP is doing that. input.val()
@jai correct me if I'm wrong the OP wants to print a number so get the val()
If I use input.is(":number") and $(this).html(input.val()); it crashes.
because the selector is wrong :number isnt a selector right?so my answer is still valid because it is a correct selector and it prints the value of input @Jai what do you think?should i just delete the answer?

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.