1

I need to allow users to input onlu numeric characters into two text boxes which are using different ID's.

        $('#signup-phone-number').keyup( function() {
            $(this).numeric();
        });

That code above is what I currently have. now i tried to change that to:

        $('#signup-phone-number', '#mobile-number').keyup( function() {
            $(this).numeric();
        });

The code above is not working. I just need to use Id's. no classes.

How I can do this please?

4 Answers 4

9

Try to use like

$('#signup-phone-number , #mobile-number').keyup( function() {
    $(this).numeric();
});

Even you can give all of them a UNIQUE class and use the event that you want on that class like

$('.common_class').keyup( function() {
    $(this).numeric();
});
Sign up to request clarification or add additional context in comments.

Comments

1

Use the selectors within the same quotes:

$('#signup-phone-number, #mobile-number').keyup( function() {
    $(this).numeric();
});

Or alternatively add a class to both of those elements and use that instead, as it's a more semantic method.

Comments

1

multiple-selector

for multiple selectors use '#signup-phone-number , #mobile-number' not '#signup-phone-number' , '#mobile-number'

$('#signup-phone-number , #mobile-number').keyup( function() {
        $(this).numeric();
    });

Comments

0
  <script>
      $(function() {
        $('#segement1,#segement2,#segement3').hide()
      });
  </script>

    <div id="segement1"></div>
    <div id="segement2"></div>
    <div id="segement3"></div>

1 Comment

While your code may answer the question, it's often useful to include an explanation.

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.