When a user clicks on the product id field, I would like to add my data underneath the table and then conduct a search

  1. When adding data to a table, I noticed that it is being added at the top instead of below the table,
  2. I implemented a search feature where the user can enter a product id, but I cannot seem to locate the error in my code,
  3. Is there a way to add a search field to all buttons without writing the code multiple times?

$(document).ready(function() {

  var url = "http://34.201.147.118:3001/getAllData";
  $.getJSON(url, function(data) {
    console.log(data);
    //console.log("AllData")
    var obj = data['AllData'];
    //console.log(obj)
    for (var i = 0; i < obj.length; i++) {
      var tr = "<tr>" +
        "<td>" + obj[i]["ProductID"] + "</td>" +
        "<td>" + obj[i]["Title"] + "</td>" +


        $("#mytable").append('<tr class="child"> tr</tr>');
    }
  });
});

function goodCall() {

  $(document).ready(function() {
    $("#id").on("keyup", function() {
      var value = $(this).val().toLowerCase();
      $("#myTable tr").filter(function() {
        $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
      });
    });
  });

}
body {
  background-image: url("banner.jpg");
  background-size: 100%;
}

#mytable {
  font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
  width: 100%;
}

#mytable td,
#customers th {
  border: 1px solid #ddd;
  padding: 8px;
}

#mytable tr:hover {
  background-color: #ddd;
}

#mytable th {
  padding-top: 12px;
  padding-bottom: 12px;
  text-align: left;
  background-color: #4CAF50;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!-- Page Content -->
<div style="margin-left:25%">

  <h1 style="color:white;">TITLE DETAILS</h1>

  <div class="w3-container" id="add">
    <div class="" style="color:white;">
      <form name="test_form" id="101">
        <table class="table borderless">
          <tr>
            <th>Title Identifier</th>
          </tr>
          <tr>
            <td style="border:none">
              <b>PRODUCT ID</b>

              <br>
              <input type="text" id="id" style="color:black;" required></td>
            <td style="border:none"></td>
            <td style="border:none">
              <b>PRODUCT TITLE</b>

              <br><input type="text" id="title" style="color:black;" required></td>
          </tr>

          <tr>
            <td style="border:none">
              <br> <b>director </b>
              <br> <input type="text" id="ter" style="color:black;" required>
            </td>
            <td style="border:none"></td>
            <td style="border:none">
              <b>producer</b>
              <br> <input type="text" id="media" style="color:black;" required>
            </td>
          </tr>

        </table>
      </form>
      <input type="button" onclick="goodCall()" value="Search" style="color:Red;">
      <table id='mytable'>
        <tr>
          <th>ID</th>
          <th>PRODUCTTITLE</th>

        </tr>
        <div>
          <br><br>
        </div>

      </table>
    </div>
  </div>
</div>

Answer №1

Here's a simple functional illustration https://jsfiddle.net/0Lvqcd8t/39/

You need to make this adjustment:

var tr = "<tr>" +
        "<td>" + obj[i]["ProductID"] + "</td>" +
        "<td>" + obj[i]["Title"] + "</td>" +


        $("#mytable").append('<tr class="child"> tr</tr>');

to this:

var tr = "<td>" + obj[i]["ProductID"] + "</td>" +
        "<td>" + obj[i]["Title"] + "</td>" +


        $("#mytable").append('<tr class="child">'+ tr+'</tr>');

In the initial example, you are creating an incorrect structure of

<tr><tr class="child><td></td></tr>
(the first <tr> is misused), and the browser will display something like
<tr>tr</tr><tr class='child'>empty</tr>
. Additionally, in the first case, the variable tr is not being interpreted correctly as a variable, so it should be placed as +tr+. At the end, I included a basic filter function that operates based on id.

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

Discover how to utilize images encoded in base64 format within webhook embeds on Discord

Can someone help me with inserting an image into a Discord embed using a webhook? I have the image saved as a base64 string obtained from a database. However, my attempts so far have only resulted in an empty embed. https://i.sstatic.net/CVs4j.png const d ...

Stopping Popups in Chrome When Printing with JavaScript

Javascript function printPage(htmlPageContent) { var newWindow = window.open("about:blank"); newWindow.document.write(htmlPageContent); newWindow.print(); } In this code snippet, we are creating a new window 'newWindow' and then using ...

Strategies for dynamically altering Vue component props using JavaScript

for instance: <body> <div id="app"> <ro-weview id="wv" src="http://google.com"></ro-weview> </div> <script> (function () { Vue.component("ro-webview", { props: ["src"], template: ` <input type="t ...

Distinguish between individuals who are sharing login credentials

At the moment, I am distinguishing users by using $_SESSION[id]. However, I have noticed that some users are sharing their login information on multiple devices at the same time. This could potentially create issues in the system. If there is a method to ...

What is the reason for the ineffectiveness of percentage padding/margin on flex items in Firefox and Edge browsers?

I am trying to create a square div within a flexbox. Here is the code I have used: .outer { display: flex; width: 100%; background: blue; } .inner { width: 50%; background: yellow; padding-bottom: 50%; } <div class="outer"> <div c ...

Angular CLI is not displaying CSS

I am currently using angular cli version 1.4.3, node version 6.11.3, and npm version 5.4.2. My goal is to retrieve records using angular2 and display them on localhost. I expected the output to look like this: https://i.sstatic.net/S8TVI.jpg however, the ...

Can data be transferred from one website to another without the use of an API?

I am a newcomer to the world of web development with basic knowledge of JS, Node, Express, Mongoose, and MongoDB. I have an exciting idea for a web application that would function like a spreadsheet, gathering user inputs to generate an output. The unique ...

Trouble generating document with Firebase setDoc()

In my current project, I am successfully creating a new user with authentication and then using the generated UID to create a new document. Here is the code snippet: const currentUser = await auth.createUserWithEmailAndPassword(email, pass); consol ...

Is there a way to remove the sign up link from the AWS Amplify Vue authenticator?

Utilizing the amplify-authenticator component from the aws-amplify-vue library to manage authentication in my application. I am currently exploring methods to disable the "Create Account" link on the front end interface, but haven't found a direct sol ...

Error in Function Due to Undefined jQuery DataTable Parameters

In the jQuery datatable column, the below JavaScript code will display either a green checkmark button or a red X button: { data: "HasPayment", render: function (data, type, row, meta) { if (data) { return '<bu ...

What is the process for clicking on the second link within a table when the values are constantly changing in Selenium RC Server?

How can I click on the second link labeled XYZ STORES? How do I print the text "Store XYZ address"? How can I click on the second link ABC STORES? How do I print the text "Store ABC address"? The links, addresses, and store names are all changing dynam ...

Unlock Buffer - JavaScript

I'm working with a simple JavaScript code snippet. let str = "Hello World"; console.log(Buffer.from(str,"utf-8")); The output is: <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64> Is there a way to extract the bytes from the Buffe ...

What makes an Angular project different from conventional JavaScript projects that prevents it from running in a browser like any other?

When attempting to run index.html from the dist folder in the browser, I encountered issues. This is different from an AngularJS application where simply importing the script file into index.html allows the application to work seamlessly. Why is it not po ...

How can I force an element to overflow without being affected by its parent's overflow style in CSS/HTML/JS, even if the parent is

I've come across many inquiries on this subject, but the proposed solutions never seem to work when dealing with ancestors that have absolute positioning. Take this example: <div id='page'> <div id='container' style= ...

Issue with custom select functionality on Internet Explorer 9

Having some issues with a select element in IE9. The links that should open the wiki page are not functioning properly only on IE9, and there is also an issue with the hover effect - the icon gets overridden by the background color when hovering over help ...

The number of subscribers grows every time $rootscope.$on is used

I currently have an Angular controller that is quite simple: angular.controller('appCtrl', function ($scope, $rootScope) { $rootscope.$on('channel.message', function () { // do something here } }); In addition, I have a ...

Coldbox handler does not receive the data from AJAX call

In my current project, I encountered a strange issue while making an $.ajax call to a Coldbox handler method. When I dump the rc scope at the beginning of the handler, there's no data in it other than my usual additions on each request. Even more biz ...

Guide on accessing JSON data within a script tag with jQuery through a bookmarklet

Currently, I am developing a bookmarklet that injects jQuery and attempts to retrieve specific data from a webpage that is built using AngularJS. The JSON data required can be found within a script tag when inspecting the page source in Chrome. <script ...

Leverage the power of JavaScript by combining it with the .on and .editableselect methods

I am facing an issue with a select input that I am trying to make both editable and trigger an ajax request using the on change JS function. However, only one of the functions is working as expected because I have used the same id for the select input twic ...

angularjs dropdown - customize selected item appearance

My dilemma involves a list of countries, each with a code and name. When the list is expanded, I aim to show "code + name" (e.g. "+44 United Kingdom"). However, once a country is selected, I only want to display the code ("+44"). Is it achievable using Ang ...