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 6663055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:27:27+00:00 2026-05-26T02:27:27+00:00

First off, I’d like to apologize for the horrid title there, but it was

  • 0

First off, I’d like to apologize for the horrid title there, but it was the best way I could think of summing up my issue.

Currently, I use a jQuery script that checks, on blur on an input:text, that the text value of the input is greater than a certain amount. If not, the input is highlighted red – but what I’d like to happen next, is to have a <p> in an adjacent column to have it’s text changed.

My HTML looks like this:

<tr>
      <td width="15%"><label for="example">Hello world</label></td>
      <td width="70%"><input type="text" class="" id="example" value=""/></td>
      <td width="15%"><p name="example"></p></td>
 </tr>

And my jQuery/css is :

<style type="text/css">
    .fail{
        border:2px red solid;
    }   
    </style>

    <script type="text/javascript">
    /* Inline, onBlur validation 
    Text */
    $('input:text').blur(function() {
        if ($(this).val().length <= 2) {
            $(this).attr('class', 'fail');
            }else{$(this).attr('class', '');}
    });
    </script>

Is it possible, on blur to somehow call the next element with the same name as the selected input’s id, and then change it’s text? I know this must be a tough dynamic puzzle to solve, but it’s something I really need.

In the past, I achieved the same effect by repeating the code for every element, but that’s not really suitable here.

Thank you for any advice you can give me!

  • 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-26T02:27:27+00:00Added an answer on May 26, 2026 at 2:27 am

    zzzzBov is correct however it would be better to use a context to improve efficiency and/or a tagname. In addition add a variable that references $(this).

    var $this = $(this);
    $('p[name="'+$this.attr('id')+'"]', $this.closest('tr')).text('foo bar baz'); 
    

    Edited after comment
    The difference between above and zzzzBov’s answer is:

    $('[name="'+$(this).attr('id')+'"]')  
    // will start traversing the DOM starting at the beginning of the 
    // document. Largest search.
    
    $('p[name="'+$this.attr('id')+'"]')
    // will first call getElementsByTagName and try to find a match, smaller search.
    
    $('p[name="'+$this.attr('id')+'"]', $this.closest('tr'))
    // will only search the contents of the closest('tr') tag 
    // that is an ancestor of your input. Even smaller search.
    

    Generally speaking being more specific with jQuery selectors can improve preformance. In addition using variable to store selected elements such as var $this = $(this); or var $myElement = $('#myElement') is more efficient than creating the same selectors over and over. Remember jQuery is as efficient as it can be with the selectors but it is up to you to use them to thier potential.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, I want to apologize beforehand, as I know there is a lot
First off I apologize if there is another post out there that answers this,
First off, I'd like to apologize in advance for not knowing this. I've been
First off, there's a bit of background to this issue available on my blog:
First off id like to note that this works when there is 1 row
First off, I think I know what's going on, but I thought I'd bring
First off: Everything works , but I would like to fine tune this a
first off I'm a noob to PHP but here is my problem. I am
First off, I would like to make clear, that I am SUPER NEW TO
First off, kudos to the amazing apache cordova team for making a platform-independent native-like

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.