Can JavaScript be used to change the style and make a hidden input field vanish from view?

Currently, I am designing a table containing dates along with numerous hidden fields.

print   "<td";
{ $dm=date('Y-m-d',strtotime("+".$i." days", strtotime($m)));
print " class=\"overflow\"  id=\"$a::$dm\" onclick=\"function1(this)\" "
print " >";
print  "<input type='hidden' id=\""."hidden:$a::$dm"."\"    name=\"hiddenfield\" value='123' >";
}   
print " </td>";

After that, my goal is to be able to click on a cell within the table which will result in adding a value to the hidden element and changing the color of neighboring cells.

However, once the JavaScript modifies the style, the hidden element becomes inaccessible causing the array length to decrease by one each time.

I have considered moving the hidden input fields outside of the table, but I am hesitant if this would solve the issue.

Javascript ........

>    days=5;
>     for (i=(c+1); i<(c+days);i++)
>     {
>     myTable.rows[r].cells[i].innerHTML = '';
>     j=myTable.rows[r].cells[i].id;//alert(i +" "+j) 
>     document.getElementById(j).style.borderRightStyle = "none";
>     document.getElementById(j).style.borderLeftStyle = "none";
>     document.getElementById(j).className = 'active'; 
>     ajj='hidden::'+j;alert(ajj);
>     //alert(document.getElementById(ajj).value)
>     alert(document.getElementsByName("hiddenfield").length);
>     }

When attempting to inspect the element, I receive a console message indicating that alert(document.getElementById(ajj).value) is null.

Answer №1

It appears that the issue lies within this specific line of code

myTable.rows[r].cells[i].innerHTML = '';

By setting the innerHTML of your table cell to an empty string, you are effectively removing everything inside the <td> tags, including any input fields. Adjusting the style will not resolve this issue.

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

Passing parameters from a div to a single page component in Vue.js: A complete guide

There is code that appears on multiple pages: <div id="contact-us" class="section md-padding bg-grey"> <div id="contact"></div> <script src="/dist/build.js"></script> </div> Included in main.js is: im ...

Simply output the integer value

Recently, I've been working on a function that I'm trying to condense into a one-liner code for a challenge on Codewars. You can find the problem here. Here's the code snippet that I currently have: export class G964 { public static dig ...

Ways to style CSS for a select element along with its dropdown menu when it is actively selected?

As a backend developer delving into frontend development and navigating the complexities of CSS, I find myself facing a challenge. In my current project, I need to establish a default CSS for the select tag. However, upon clicking on this tag, the border c ...

Deliver a universal Angular application using NodeJS and ExpressJS for the server-side functionality

I have set up a Node/Express JS back-end on an AWS instance using a Linux image, along with NGINX as the web server. Currently, my MEAN application is running smoothly as I work on building the Angular application. I copy the dist folder to the Node/Expres ...

Prefering `window.jQuery` over the yarn version

I am currently in the process of transitioning to Vite 3 with Vite Ruby on Rails from Webpacker and Webpack. One major issue I have encountered is that my system functions as a CMS. Some of our long-standing clients have jQuery code embedded directly withi ...

Bootstrap dropdown menu fails to expand

I recently attempted to implement a hamburger menu using Bootstrap on my website. After checking and adding the necessary CSS and JS files, I encountered an issue where the menu wasn't expanding as expected. I followed the example code provided on the ...

Prevent form submission from refreshing the page by using jQuery and ajax

I'm looking to submit a form without refreshing the page, but my current script isn't working as expected: $('#formId').submit(function(e){ $.ajax({ type: "POST", url: 'serverSide.php', data: $(&ap ...

Reactjs encountered a problem with the click event

I seem to be facing a small issue with my react component code. I can't seem to figure out what's wrong. Here's the component code: import React, { Component, PropTypes } from 'react'; import styles from './Menu.css'; im ...

Flask Modal fails to function properly in the absence of table data

I'm currently troubleshooting an issue with my modal on a Flask web app that utilizes a SQLite database. When trying to add new rows to the table using some JavaScript code, everything works perfectly unless the table is empty. In that case, I am unab ...

What is the best way to remove bootstrap when transitioning to a new microfrontend?

Our team is facing an issue with styling when using a combination of React, Bootstrap, and Tailwind. The problem arises when linking our micro frontend to modules that use Tailwind, as the Bootstrap styles persist despite the change. Since both Tailwind an ...

Can you explain the purpose of the datalayer.push function?

I've been puzzling over this.. It seems like data layer.push is simply updating the second amount. Can someone shed light on what exactly is happening here? function dollarz() { var amount1 = '$156.86'; var amount2 = amount1.replace(&quo ...

What is the optimal approach for importing node modules using var or const?

When it comes to requiring node modules like express or bodyParser, the commonly used keyword to create a variable and assign the module is var. However, is it possible to use const to declare such modules instead? In other words, instead of the following: ...

the iframe is not properly displaying the embedded responsive page

The primary webpage incorporates the responsive mobile page created with the JQUERY SUPERSLIDES plugin. The mobile page appears correctly when viewed directly on an iPhone using Safari. However, when it is embedded in an iframe, it does not display as expe ...

Is it possible to invoke a computed property within the props of a child component in Vue.js?

In the context of my child and parent components, I have a boolean prop in the child component with a default value of false. When calling the child component within the parent component and setting it based on a computed function that returns a boolean va ...

Generate the Xpath for the mentioned href element to use with Selenium Webdriver

I need help creating the Xpath for a specific href element using Selenium webdriver with only IE browser. The HTML code I am working with is as follows: I am looking to find the Xpath for: . Can someone assist in generating the correct Xpath expression ...

The validator function is causing an error with the 'lowerCase()' method resulting in an undefined output

Dealing with email validation in a form, I encountered a case-insensitivity issue. Using the angular validation mustMatch to ensure emails match index for index, I needed to address the case sensitivity. This led me to create the matchCaseInsensitivity fun ...

The output of jQuery('body').text() varies depending on the browser being used

Here is the setup of my HTML code: <html> <head> <title>Test</title> <script type="text/javascript" src="jQuery.js"></script> <script type="text/javascript"> function initialize() { var ...

Suggestions to reduce our website loading time

Query: How can one effectively reduce the file size of a webpage to improve loading speed? What specific optimization practices and coding techniques (in JavaScript and PHP) can be implemented to decrease page weight? Motivation: After reading an article ...

How to Limit the Number of Rows in a Vue.js Bootstrap Table

Is there a way to display only the first row of a Bootstrap table initially, and then reveal the rest of the rows using a checkbox? Keep in mind that the Bootstrap table and checkbox are located in different components. <b-table hover small responsive b ...

How to include an array of data in an $http request using AngularJS

I am trying to store data in an array to the $http service in AngularJS. The way I am currently adding them to the service is as follows (and it is functioning correctly): var inputValueArray = new Array($scope.formdata); Currently, I am able to retriev ...