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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:26:11+00:00 2026-05-16T17:26:11+00:00

I have the following text box input code. I do not have access to

  • 0

I have the following text box input code. I do not have access to it to add the default value to it so i used this Jquery code to add the value and then disable the input but it doesn’t send the added value. How would I add the value but not allow them to change it. I was going to use “hidden” but I want them to see it just not able to change it.

$("input[type='text'][name='ShipCity']").val('Madison').attr('disabled', 'disabled');



<input type="text" style="background-color: rgb(255, 255, 0);" value="" name="ShipCity" maxlength="45" size="25">
  • 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-16T17:26:12+00:00Added an answer on May 16, 2026 at 5:26 pm

    EDIT: Another option would be to disable the fields, and enable them when you submit the form:

    $("input[type='text'][name='ShipCity']").val('Madison').attr('disabled', 'disabled');
    
    $("form").submit(function() {
        $(':input', this).removeAttr('disabled');
    });
    

    I think this should work anyway.


    Original answer:

    This will return false; on keypress events.

    Also, it stores the default value using jQuery’s .data(), and checks that value in a blur event handler.

    The reason for this is that it is possible to enter a new value without a keypress event (via the GUI menus).

    $("input[type='text'][name='ShipCity']")
        .val('Madison')                  // give default value
        .data('defaultVal', 'Madison')   // remember default value
        .keypress(function() {
            return false;                // prevent keypress events
        })
        .blur(function() {
            if(this.value !== $.data(this, 'defaultVal')) // set back to the default
                this.value = $.data(this, 'defaultVal');  //   if it was changed via
        });                                               //   the GUI menu
    

    EDIT:

    Here’s a version that will let you do it so that you only need to type the default value once. (It is otherwise identical.)

    Example: http://jsfiddle.net/cdzuR/

    $("input[type='text'][name='ShipCity']")
        .data('defaultVal', 'Madison')  // You only need to give the default once
        .val(function() { return $.data(this, 'defaultVal'); })
        .keypress(function() {
            return false;
        })
        .blur(function() {
            if(this.value !== $.data(this, 'defaultVal'))
                this.value = $.data(this, 'defaultVal');
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jQuery code that shows an input box if yes is
I have the following code to validate two text box entries to make sure
I have used the following code to generate some dynamic checkboxes. This works for
In the following code i am trying to have a text box and a
Say I have a textbox in HTML using the following code: <input type=text name=text
I have progress.js file which has the following code $('#text_area_input').keyup(function() { var text_area_box =$(this).val();//Get
I have the following HTML code for dialog box: <div id=modal-dialog class=no-display> <div class=form>
jQuery 1.7.1 - I have an array of input text elements (class - pr)
I have the following code: $(#auto).autocomplete({ source: js/search.php, minLength: 3 }); This code is
I have an html text box with some having class names as numbers <input

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.