The value of input[text] cannot be set as it is undefined

I am having trouble retrieving the value property from input[type='text'] with IDs #page-name and #page-url as it is showing up as undefined :

 eventsDispatcher: function() {

   var self = this;

   $(".b-row a").click(function() {

     var tileId = ("this").id;
     $("#tile-edit").css("display", "block");

     $("#tile-edit-save").click(function() {

       self.pageList[tileId].name = $("#page-name").val(); // -> here
       self.pageList[tileId].url = $("#page-url").val(); // -> here
       console.log(self.pageList[tileId].name);
     });
   });
 },
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<div id="tile-edit">

  <form>
    <table>

      <tr>
        <td>
          <label for="page-url">Adress</label>
        </td>
        <td>
          <input type="text" name="page-url" id="page-url" class="">
        </td>
      </tr>

      <tr>
        <td>
          <label for="page-name">Name</label>
        </td>
        <td>
          <input type="text" name="page-name" id="page-name" class="">
        </td>
      </tr>

      <tr>
        <td>
          <input type="button" id="tile-edit-save" value="save">
        </td>
      </tr>

    </table>
  </form>

</div>

The rest of the code works perfectly fine, including both .click functions, I just can't seem to understand why it's not fetching the values for #page-name and #page-url ??

Answer №1

My assumption is that ("this").id will likely result in undefined. Consider updating it to:

var tileId = $(this).attr('id');

Answer №2

It appears that there are special characters in your HTML code. I recommend copying and pasting it into a plain text editor to see if that resolves the issue. Feel free to share the form HTML here for further assistance.

$('#tile-edit-save').on('click',function() {
console.log($("#page-name").val())
console.log($("#page-url").val())
});
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <form>
  <table>

    <tr>
      <td><label for="page-url">Adress</label></td>
      <td><input type="text" name="page-url" id="page-url" class=""></td>
    </tr>

    <tr>
      <td><label for="page-name">Name</label></td>
      <td><input type="text" name="page-name" id="page-name" class=""></td>
    </tr>

    <tr>
      <td><input type="button" id="tile-edit-save" value="save"></td>
    </tr>

  </table>
</form>

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

Error: Unable to locate npm package

I am currently working on an Angular application that was created using Grunt and relies on Bower and NPM. Recently, I attempted to install an npm module locally. The installation resulted in the files being stored in the main application directory under ...

Get all elements in jQuery that have names beginning with the specified selector

I am currently working on a form that includes a SELECT element and several input fields. The segment related to Monday is shown below (note that there will be 7 days in total): <div class="row"> <div class="col-md-3"> <div clas ...

How can we assign identical names to multiple textboxes generated by a loop?

I have a dynamic creation of multiple textboxes or textfields in JSP using a for loop. The quantity is determined at runtime based on a condition, so I can't specify the exact number. Each textbox has an onFocus event that triggers a function such as ...

Utilizing Material-UI TextField with targeted onChange event handler

I wrote a function that iterates through an array of objects and creates material-ui TextField elements based on the information provided. The goal is to display an error message if the user inputs characters exceeding the defined maxLength. I want the er ...

Is there a way to transform a Phaser 3 game into an android-game application?

As someone who is new to Phaser, I am curious about the possibility of converting a Phaser game into an Android game. Currently, I am utilizing Phaser with NPM for my projects. Any insights or advice on this matter would be greatly appreciated. Thank you! ...

Using angular.copy function to copy an array with a custom property

Let's use the example below to illustrate an issue: var ar = [4, 2, 3]; ar.$x = 'something'; var br = angular.copy(ar); console.dir(br); After copying ar to br, the $x property is no longer present. This is because when Angular copies an a ...

How to automatically open JQuery Accordion panels when the page loads

My Accordion loads with the 1st panel open upon page load, but I am looking for a way to have the entire Accordion closed by default. Any help or suggestions on how to achieve this would be highly appreciated. Thank you for your assistance. FIDDLE http:// ...

Preventing window resize from affecting print screen content in Angular 8

I'm struggling with a print button feature in my Angular 8 project. When the window is resized, the content within the print window also resizes, which is not the behavior I want. I've tried a couple of solutions, but nothing has worked so far: 1 ...

Material-inspired Design Device Compatible DIV slide with JS, JQuery, and CSS

My goal is to achieve something similar to this: Desired Live Website I am looking for a feature where clicking on the div will slide in content from the right, load an external page inside it, and close when prompted. The slider div should be device c ...

Updating a JSON property in JavaScript on the fly

I am looking to dynamically replace the content of "placeholder" with {"John": "Dough"} using a function call. This initial method seems to work fine: a = {foo:{bar:{baz:"placeholder"}}}; a.foo.bar.baz = {"John" : "Dough"}; console.log(JSON.stringify(a)) ...

Sort activities according to the preferences of the user

This is the concept behind my current design. Click here to view the design When making a GET request, I retrieve data from a MongoDB database and display it on the view. Now, I aim to implement a filter functionality based on user input through a form. ...

Utilizing Bootstrap 3 to eliminate the blue border surrounding the Contact Button

Recently, I integrated Bootstrap 3 into my website and encountered an issue. After selecting the Contact button and closing the popup window, it remains highlighted which is not desirable. https://i.sstatic.net/pzfKy.png I want to modify my CSS file so t ...

Exploring Google Charts: Creating Double Bar Charts Using Dual Axis on Internet Explorer

I have encountered an issue while trying to create multiple bar charts with dual axes on the same page. Everything works perfectly in Chrome, but unfortunately it does not function properly in IE. When viewing the charts in IE, an error message appears: ...

Take action once you have obtained the output from jQuery UI Autocomplete

Is there a way to trigger an action after receiving results in jQuery UI Autocomplete, or am I missing something? Here's what I'm attempting to do: as a user types in an address in the input field, Autocomplete provides suggestions. I want all t ...

Automatically select a value in MUI AutoComplete and retrieve the corresponding object

I recently set up a list using the MUI (v4) Select component. I've received a feature request to make this list searchable due to its extensive length. Unfortunately, it appears that the only option within MUI library for this functionality is the Au ...

Tips for utilizing the Ace editor validator without the need to create a new Ace editor instance

In my React application, I utilize react-ace to build a CSS text editor. The implementation looks something like this... import Ace from 'react-ace' ... <Ace mode="css" value={value} onChange={onValueChange} onValidate ...

Stepper wizard experiences a variation in CSS styling when minified

Two plunkers showcasing material design wizard selectors are causing different behavior upon stepper clicks. One uses a minified version of CSS while the other is expanded. The issue arises with the transition effects in the .step-wizard .progressbar class ...

Revamping the Jquery Waypoint

Greetings, I am currently delving into the world of Jquery waypoints and facing a bit of challenge getting it to work. My goal is to have an "alert" pop up once an element becomes visible on the screen, but for some reason, the alert doesn't show up w ...

Error: Undefined variable in JavaScript obfuscation

My website has several small JavaScript files that I currently merge into one file and then minimize using terser. The website functions perfectly with the minimized version. Now, I want to take it a step further and obfuscate the code using JavaScript-Ob ...

Leveraging .intersect/.intersectsBox to handle object collisions in threeJS

Currently, I am developing a simple breakout/arkanoid game using threeJS. The game features a paddle and a bouncing ball on the screen. My main focus right now is to make the collision detection work correctly so that when the ball hits the paddle, it boun ...