Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3933190
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:34:22+00:00 2026-05-19T23:34:22+00:00

I have a textbox and labels inside rows of a table. To access the

  • 0

I have a textbox and labels inside rows of a table. To access the textbox I’m using
data= $(this).find('#txtName').val();

Now I’m not able to access the label in the same way. The label is rendered as
<label for="Total">$65.00</label>

How can I access the label’s value and assign a value to it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:34:22+00:00Added an answer on May 19, 2026 at 11:34 pm

    It’s hard to say when you haven’t shown your HTML structure, but a couple of possibilities:

    1) The label is separate

    If your label is separate, like this:

    <tr>
    <td><label for='txtName'>Some field</label></td>
    <td><input type='text' id='txtName'></td>
    </tr>
    

    …then given the id of the textbox is txtName, you can use an attribute selector to search for the label with that for attribute:

    var label = this.find("label[for=txtName]"); // If the label is also within `this`
    // or
    var label = $("label[for=txtName]");         // Find it no matter where it is
    

    Edit: So if the name of the field is Total, it would be:

    var label = this.find("label[for=Total]"); // If the label is also within `this`
    // or
    var label = $("label[for=Total]");         // Find it no matter where it is
    

    To set its contents (not “value”), use either text or html:

    label.text("Field name");
    label.html("Field <em>name</em>");
    

    2) The textbox is within the label:

    Edit: Now that Drackir has fixed the formatting of your post, we can see that you’re using the for attribute as above. Keeping this second part in case someone else sees this and is doing it this way.

    If the textbox is within the label, like this:

    <tr>
    <td>
    <label>Some field: <input type='text' id='txtName'></label>
    </td>
    </tr>
    

    …then if $(this).find('#txtName').val(); works, this should work:

    var textBox = $(this).find('#txtName');
    var label = textBox.parents('label');
    // Do something with `textBox.val()` and `label`
    

    (If the textbox really is an immediate child of the label, you could use .parent() instead of .parents('label'), but the latter is useful if the text box is a descendant rather than an immediate child.)

    Once you have the label, you can’t just set its content via text or html because you’ll wipe out the field (since it’s inside the label). You could do this:

    var textBox = $(this).find('#txtName');
    var label = textBox.parents('label');
    textBox.detach(); // temporarily remove from the DOM
    label.text("Field name: ");
    textBox.appendTo(label);
    

    That temporarily removes the text box for safekeeping (detach leaves event handlers in place), sets the text of the label to “Field name: “, and then appends the textbox back to it.

    More:

    • Selectors
    • text
    • html
    • parents
    • parent
    • Traversing
    • detach
    • appendTo
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textbox and some labels inside the data template of bounded listbox.
hello everybody i have a listbox within which is a datatemplate.Inside it is checkbox,textbox,label...Wat
This is my problem, I have one textbox, one button and one label. Everything
I have a TextBox that is inside of a RadioButton's label. In FireFox (v8.0.1),
I have a Panel control. And inside the panel users can add combobox's, textbox's
I have a few textboxes/labels inside of an UpdatePanel. When I tab out of
I have a DetailsView Control, inside as a template a TextBox. I need to
I have a TextBox inside my .Aspx page: <ajax:UpdatePanel ID=UpdatePanel2 runat=server> <ContentTemplate> <asp:TextBox ID=txtCity
I am working on creating a Firefox extension. I have added a textbox inside
I have a few tab spaces with my text inside a TextBox, and when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.