Enhance Object within one function using another function to increase its worth

How can I update the value in a chaseObj from a method in another object? Any advice would be greatly appreciated. Thank you!

var s, searchUts;
var getValue = '';
var generateObject = function() {
  var chaseObj = {
    "timeFilters" : getValue
  };
  return chaseObj;
};

searchUts = s = {
  createValue: function() {
    var x = 10;
    var y = 20;
    getValue = x + y; // Add this value to chaseObj inside the generateObject function
  },
  postToBackEnd: function() {
    var chaseObj = generateObj();
    $.ajax({
      url: localhost:8080/site/home,
      data:JSON.stringify(chaseObj) // The chaseObj is not updated with the new value here

    })
  }

};

Answer №1

It's not clear what you're seeking, but could this be the desired outcome?

var s, searchUts;
var getValue = '';
var generateObject = function() {
  var chaseObj = {
    "timeFilters": getValue
  };
  return chaseObj;
};

searchUts = s = {
  createValue: function(obj) {
    var x = 10;
    var y = 20;
    obj.timeFilters = x + y; // add this value to chaseObj within generateObject
  },
  postToBackEnd: function() {
    var chaseObj = generateObject();
    this.createValue(chaseObj);
    console.log(JSON.stringify(chaseObj));
  }
};

s.postToBackEnd();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The tilesloaded event in google.maps.event.addListener is unexpectedly failing to trigger

Today, while testing popover messages on my cordova/ionic app, I compiled the app and noticed that the maps weren't loading. Instead, only my custom "Loading map..." spinning icon kept showing. Upon investigating further, I found that var setMap = n ...

Countdown timer feature and auto-submit function for your website's page

Currently, I am working on an online exam project that requires the page to be automatically submitted after 10 minutes, regardless of whether the user clicks on the submit button or not. Additionally, I want to include a countdown timer to display the r ...

What are the alternative methods to execute a React.js application without using react-scripts?

After creating my React.js app using the command below: npx create-react-app my-app I'm now looking to modify the package.json script section to run the app without react-scripts. How can I achieve this? "scripts": { "start&quo ...

Creating arrays in JavaScript with or without the use of jQuery

In my JavaScript script, I am defining this array: var status=[ { "name":"name1", "level":0 }, { "name":"name2", "level":0 }, { "name":"name3", "level":0 }, { "name":" ...

How can you preselect an item in Vuetify's item group?

When attempting to preselect an item from a vuetify item-group, I discovered that it works with strings but not with objects. The vuetify documentation shows using a string array as the item list for the item-group, which functions correctly. However, whe ...

Using Bootstrap, jQuery, and PHP to dynamically load input fields in a modal window

I am looking to dynamically load input fields in a modal window using PHP. While researching, I came across suggestions to utilize AJAX for this purpose. However, I have limited knowledge about AJAX. The plan is as follows: 1) When the user clicks on the ...

Adjust the position of the footer up or down based on changes in page content height

If I have jQuery at my disposal, how can I achieve the following task? There is a div on the page with dynamic content and no fixed height. The height of this div changes as users type and content appears or disappears accordingly. Although everything is ...

Enhance your SVG image in D3 by incorporating a drop-shadow effect

Trying to apply a drop-shadow effect to an SVG image using D3. Check out my code below and see the example block here: var imgurl = 'http://www.logo-designer.co/wp-content/uploads/2015/08/2015-Penn-State-University-logo-design-4.png'; var mar ...

Ruby On Rails: Dealing with Partial Page Loading

As a newcomer to Ruby on Rails, I'm struggling to find answers to an issue I'm facing in my web app. After a few clicks in my development environment, some pages stop loading data abruptly without any error messages in the console or Firebug. The ...

Error 404 encountered when attempting to send a JSON object to the server

I've been facing a problem while trying to send a JSON object to the server using AJAX calls. I keep getting a 404 Bad Request error. The issue seems to be related to the fact that I have a form where I convert the form data into a JSON object, but th ...

What is the best way to distinguish a particular item in a <select> element and include a delete button for each row using jQuery?

1.) I've set up a nested table and now I want to ensure that when the 'Delete' button within the child table is clicked, its corresponding row gets deleted. 2.) I have a <select> tag. The issue is how can I implement validation to che ...

Sending data from the View to the Controller using AJAX in Laravel 5

Data I have some data stored in a variable var info = []; info['upnp_enabled'] = $("#upnp-switch").val(); When I console.log(info);, the output shows [upnp_enabled: "true"] Ajax I attempted to send a PUT request to my Cont ...

Determine the closest parent using jQuery

When using jQuery, the closest function can be called to locate the nearest parent element. For instance, if there is an a within a li within a ul within a td within a table, determining whether the ul parent is closer than the table parent may not always ...

The video is not appearing on mobile devices using Safari, Firefox, and Chrome, but it is displaying properly on desktop computers

My website has a video in the header that works fine on desktop but not on mobile. I am using next.js 13.4 and here is my code: <video id="background-video" autoPlay playsInline loop muted classN ...

Transform object into an array by flattening it

I'm currently working on a task where I have an object that needs to be transformed into an array with the property as the key. The structure of the object is as follows: { Cat: { value: 50 }, Dog: { value: 80 } } The desired output should ...

AngularJS ng-repeat filtering by date is there any solution?

I have a ng-repeat loop with dates in the format below: <small>Added: <strong>{{format(contents.completeddate)}}</strong></small> I am using a datepicker plugin that provides me with 2 objects - a start date and an end date. For ...

The website on iPad automatically zooms in upon opening and then increases the zoom level even further when a specific button is tapped

I recently coded a website using html, css, and js. It seems to work perfectly on all devices except for the iPad. Interestingly, when I use the iPad emulator in Google Chrome, everything appears normal. However, when I open the website on an actual iPad, ...

jQuery Autocomplete with Link Options

Can anyone help me with creating a search function for my charity's internal website? I've managed to get it partially working, but I'm struggling to make the results link to the right places. Below is the code I have so far, including test ...

Tips on retrieving Bootstrap selectpicker value by using loops in Jquery

I am attempting to perform a basic validation using jQuery, where I need to iterate through all elements to check for the existence of values. The validation script is working well except for the jQuery selectpicker functionality. Here's what I have t ...

Matching names with corresponding IDs from multiple arrays in React

In my React app, I am dealing with an array structure. There is one array that contains the ids of two other arrays, along with their respective names. The goal is to create a new array that combines all the necessary information. Here is a simplified vers ...