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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:59:08+00:00 2026-06-18T09:59:08+00:00

Since I am a complete n00b in every aspect when it comes down to

  • 0

Since I am a complete n00b in every aspect when it comes down to JS, JQuery and PHP, I will be needing some help.

Probably it’s really simple for someone with basic knowledge of JS, but it ain’t that simple for me.

I have the following part in my index.php:

<form method="get" id="searchform" action="http://wwwapps.ups.com/WebTracking/track?HTMLVersion=5.0&loc=nl_NL&Requester=UPSHome&WBPM_lid=homepage%2Fct1.html_pnl_trk" target="_blank" >
<input type="text" value="" name="trackNums" id="ups" />
<input type="hidden" name="track.x" value="Traceren">
<input type="hidden" name="loc" value="nl_NL">
<input type="image" src="afbeeldingen/search_btn.png" id="searchsubmit" />
</form>

In the .js file I have this:

$(document).ready(function() {
    $("#ups").attr("value", "UPS Trackingscode...");
    var text = "UPS Trackingscode...";
    $("#ups").focus(function() {
        $(this).addClass("active");
        if($(this).attr("value") == text) $(this).attr("value", "");
    });
    $("#ups").blur(function() {
        $(this).removeClass("active");
        if($(this).attr("value") == "") $(this).attr("value", text);
    });
});

I added this (at the top of) the .js file:

function removeSpaces(string) {
    return string.split(' ').join('');
}

But when I add this part to the index.php (form-section) it doesn’t work:

<input type="text" onblur="this.value=removeSpaces(this.value);">

I guess I have to incorporate it to the current JS as well, but I have no clue how to do this or what to change / add.

What I am trying to achieve here, is that whenever I paste a trackingcode into the text field, it should automatically remove the spaces (if there are any, because a bad copy/paste action).

It’s not for any special website, but just for my personal use, so I can track packages more easily from my own starting page.

I hope I explained it correctly. Probably it takes less than a minute for someone with basic JS skills, but for me it’s very difficult. 🙁

  • 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-18T09:59:09+00:00Added an answer on June 18, 2026 at 9:59 am

    The function itself is working well. It’s solely a scoping issue. You have two options:

    1) You move your function outside the $(document).ready(function() { }) part

    2) You remove the onblur="this.value=removeSpaces(this.value);" from your element, discard your function and write an according event-handler

    // identifier or class needed to target the element, i use id="target"
    $("#target").on("focusout",function(){
       this.value = this.value.replace(/\s*/g,"");
    });
    

    The second way (using event handlers) is considered the cleaner and better way. But valid are both.

    Sidenotes:

    to remove spaces from your string, it’s better to use the replace method with an according regular expression /\s*/g (replace zero or more whitespaces \s* in your entire string (globally g) ).

    Instead of $(this).attr("value") use $(this).val().

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

Sidebar

Related Questions

Since silverlight doesn't have complete TimeZoneInfo I will need to implement some of the
Since regular jQuery animations are not fluent on iOS ( .hide() , slideDown() ),
Since REST is stateless, each request that comes in has no knowledge of the
Sorry, I'm not even sure how to ask, since I'm a complete newbie at
I'm a complete newbie and am building a HTML5 app with PhoneGap which will
Since I do not have access to the complete source code of a library
Since there's no complete BPM framework/solution in ColdFusion as of yet, how would you
Since the value of forKey is a NSString, where do I find a complete
Since Android 4.2 if a user downloads some file in the browser the DownloadManager
since I'm trying to solve this problem for some days, I thought about giving

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.