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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:18:18+00:00 2026-05-15T16:18:18+00:00

How can I disable an input-field with jQuery using GM if the url contains

  • 0

How can I disable an input-field with jQuery using GM if the url contains text?

I tried

$(document).ready( function() {
    if($("url:contains('text')")){
        $(".input[id=field-owner]:disabled");
    }
    else {
        $(".input[id=field-owner]:enabled");
    }
});

I don’t know what I did wrong. And I also don’t know whether url:code is a regular expression to use.

Update

Hi again,
thanks for your time putting in this. I guess it’s easier to ask/answer how to call an alert when the url contains e.g. “newthread”.

So, we have got a url(e.g.): http://forum.jswelt.de/newthread.php?do=newthread&f=1 ,
and an input-field with id=”subject” and a label for “subject”.
If the url contains “newthread” the input-and label-element should be hidden.
Following code works, but not for me. The console says nothing and won’t alert though.


var url = window.location.href 
url = "http://forum.jswelt.de/newthread.php?do=newthread&f=1";
    var pos = url.search(/newthread/); 
    if(pos >= 0)
        alert("tadaa");
    else
        alert("mist");

🙁

Thank you to all helping me.

Edit inserts the final solution


if (location.href.indexOf("text") != -1) {
$('#fieldname').attr("disabled", true); 
  • 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-15T16:18:18+00:00Added an answer on May 15, 2026 at 4:18 pm

    Throw away that snippet. Should be like

    (function($){
      $(document).ready(function(){
         var url = window.location.href;
    
         if(/text/g.test(url)){
            $('#field-owner').attr('disabled', 'disabled');
         }
         else{
            $('#field-owner').removeAttr('disabled');
         }
      });
    })(jQuery);
    

    edit

    “$ not defined” means you either aren’t loading the jQuery library or $ gets overwritten.
    I put the whole snippet into a self-executing anonymous function which will fix the last issue at least.

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

Sidebar

Related Questions

With jQuery, I'm trying to disable an input field like this: <input id=submit type=image
In C++ you can disable a function in parent's class by declaring it as
I'm using Jörn Zaefferers autocomplete plugin for jQuery to enable a live search field,
I want to disable users from entering a character into a HTML text input
I've two input fields, both type textareas. <input id=display type=text disabled=disabled style=border: none; background:
I know this seams a trivial question, but how can I disable the annoying
Can I somehow disable spell-checking on HTML textfields (as seen in e.g. Safari)?
I can't seem to be able to disable ViewState for controls that I add
I can't seem to be able to disable a select box when the select
Can any script or setting be written (autorun file?) to disable formatting of a

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.