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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:45:53+00:00 2026-06-03T14:45:53+00:00

I found this link very useful get selected textbox id jQuery however, what i

  • 0

I found this link very useful

get selected textbox id jQuery

however, what i wanted to do now is to reuse this id to do some trimming function for each textbox where it is actually looping. I have tried this code:

<html>
    <head>
        <?php   echo $this->Html->script("jquery-1.4.3.min"); ?>

    </head>
    <body>
    <?php
        echo $content_for_layout;
    ?>
    <script type="text/javascript">
        $(document).ready(function () {
         //       alert('JQuery is succesfully included');

/*      $(':submit').click(function(){
            <?php if(($this->request->controller=='members')&&($this->action=='register')):?>
                    //alert('well');
                    var some = $.trim($(":text").val());
                    alert(some);
            <?php  endif; ?>

            });
*/
            $(':submit').click(function(){
                $('form input[type="text"]').each(function(){
                    //get value of id of textbox here
                    var id = $(this).attr('id');
                    var some = $.trim($((this).attr('id')).val());
                    alert(some);
                });

            });
        });
    </script>
    </body>
</html>

yet it doesnt pops out the alert box.

  • 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-06-03T14:45:55+00:00Added an answer on June 3, 2026 at 2:45 pm

    I’m a bit confused about exactly what you are trying to achieve, but there is a problem on this line:

    var some = $.trim($((this).attr('id')).val());
    

    Specifically, (this).attr('id') doesn’t work because (this) is interpreted as this and this is the current DOM element which doesn’t have an .attr() method.

    I think you probably wanted to do this:

    var some = $.trim($("#" + $(this).attr('id')).val());
    // or, given you already have a variable id equal to $(this).attr('id')
    var some = $.trim($('#' + id).val());
    

    That is, you are trying to get the id from the current element then use that id to select the element and get its value, then trim the value. But you don’t need the id to get the value given you already have a reference to the element – you can just do this:

    var some = $.trim($(this).val());
    // or
    var some = $.trim(this.value);
    

    If you want to loop through all the textboxes and set them to the trimmed version of their current values you can do this:

    $('form input[type="text"]').each(function(){
        this.value = $.trim(this.value);
        // or if you want the slower and harder to read way:
        $(this).val( $.trim($(this).val()) );
    });
    

    Or:

    $('form input[type="text"]').val(function(i,currentVal) {
        return $.trim(currentVal);
    });
    

    See the .val() doco for information about passing a callback function to .val().

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

Sidebar

Related Questions

I have found some info on the subject ( like this link) , but
Some days ago, I have found a useful link in which a day on
I have found some useful info on this issue but can't quite wrap my
I found this link. Very cool. That shows how you can store appsettings in
I have been using jQuery's find method and it's been very useful. However, I
I found this link http://artis.imag.fr/~Xavier.Decoret/resources/glsl-mode/ , but there isn't a lot of description around
I found this link on how to embed custom fonts in XAML apps. Is
i have a problem using the Catch Clipboard Events code found on this link
I've found a code which opens this link after logging in to google account
Found this is some example CSS I was reading and I'm having a hard

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.