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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:37:27+00:00 2026-05-18T04:37:27+00:00

How do I properly load the a certain value into a textbox using jQuery?

  • 0

How do I properly load the a certain value into a textbox using jQuery? Tried the one below but I get the [object Object] as output. Please enlighten me on this, I’m new to jQuery.

proc = function(x, y) {
  var str1 = $('#pid').value;
  var str2 = $('#qtytobuy').value;
  var str3 = $('#subtotal').load('compz.php?prodid=' + x + '&qbuys=' + y);
  $('#subtotal').val(str3);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<form name="yoh" method="get">
  Product id: <input type="text" name="pid" value=""><br/> 
  Quantity to buy:<input type="text" name="qtytobuy" value="" onkeyup="proc(document.yoh.pid.value, this.value);"></br>

  Subtotal:<input type="text" name="subtotal" id="subtotal" value=""></br>
  <div id="compz"></div>

</form>
  • 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-18T04:37:28+00:00Added an answer on May 18, 2026 at 4:37 am

    I think you want to set the response of the call to the URL 'compz.php?prodid=' + x + '&qbuys=' + y as value of the textbox right? If so, you have to do something like:

    $.get('compz.php?prodid=' + x + '&qbuys=' + y, function(data) {
        $('#subtotal').val(data);
    });
    

    Reference: get()

    You have two errors in your code:

    • load() puts the HTML returned from the Ajax into the specified element:

      Load data from the server and place the returned HTML into the matched element.

      You cannot set the value of a textbox with that method.

    • $(selector).load() returns the a jQuery object. By default an object is converted to [object Object] when treated as string.

    Further clarification:

    Assuming your URL returns 5.

    If your HTML looks like:

    <div id="foo"></div>
    

    then the result of

    $('#foo').load('/your/url');
    

    will be

    <div id="foo">5</div>
    

    But in your code, you have an input element. Theoretically (it is not valid HTML and does not work as you noticed), an equivalent call would result in

    <input id="foo">5</input>
    

    But you actually need

    <input id="foo" value="5" />
    

    Therefore, you cannot use load(). You have to use another method, get the response and set it as value yourself.

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

Sidebar

Related Questions

We're using Hibernate to load objects that meet certain criteria. If the user decides
I am using 3 unbound DataGridView controls to display certain information. To load the
How do I get the LOAD DATA INFILE command to skip certain fields. Lets
The first stage that I load it always open properly as fullscreen. stage.setFullScreen(true); stage.setScene(login_scene);
Sometimes the header of my website does not form properly when I first load
Our web app uses SystemPropertyPlaceholder to load property files depending on the value of
This code compiled properly on Visual Studio 2010 on Windows, but I'm getting this
I have a re-occurring design problem with certain classes which require one-off initialization with
In one of requirement we have to make available certain attributes through out the
Basically I want to load a HTML document and using controls such as multiple

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.