Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript How do I use a wildcard value in my javascript?

HBNA

New Coder
I need to run the below javascript code on any name that begins with text-15. Here is my beginning code that runs with text-15. But I need it to run when the value changes to something like text-15-18764juv and this value may change to something else. So a wildcard: text-15*

JavaScript:
<script type="text/javascript">
        $(document).ready(function() {
            $("#text-15").keypress(function (e) {
                if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
                    do something;
                    return false;
                } else {
                    do something;
                }
            });
        });
</script>

Can someone help? Thanks
 
I don't quite understand what you are writing here:
I need to run the below javascript code on any name that begins with text-15
What you you mean with any "name"? If I understand correctly (but I'm no jQuery adept) your JS code creates a keypress listener for the element with id text-15. How could that id change to something else ? Changing id's does not seem something you'd want to do.
Or do you mean that you have multiple elements, each with an id starting with text-15, and you want to create keypress events for each of them ?
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom