0

I'm new to jquery. I have a MVC code which is a form having textboxes with id's from 0 to n. There is an add button, on clicking it an extra text box is created and continues until user wishes to add as many text boxes as he can. Now I want to convert the text inside text boxes from lowercase to uppercase using jquery. I know how to do for a single text box, but how can i access when the textbox id's are in for loop. Here is an example of my text box id's

<input type="text" id="txt[i]", value = "box[i]">

i value varies from 0 to n as long as user wants to insert n no. of text boxes dynamically.

PS: I'm newbie to Stackoverflow too. Please dont mind for code format as idk how to post code here.

2
  • Does my answer solve your problem? Commented Apr 13, 2020 at 8:06
  • Thanks Selim, but it didn't solve my prob. :( Commented Apr 13, 2020 at 8:16

1 Answer 1

1

You can select textboxes by class instead of id, and use jQuery.each(), so that you don't need to know id's.

First adding class attribute:

<input class="tbUpperClass" type="text" id="txt[i]" value="box[i]">

Then script would be like:

$(".tbUpperClass").each(function (index, value) {
    var text = $(this).val();

    //Converting text to uppercase and set textbox value
    $(this).val(text.toUpperCase());

});

See: Jquery class selector

Sign up to request clarification or add additional context in comments.

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.