Table featuring identical submit buttons in each row: initial submit button is nonfunctional (potential issue with multiple identical IDs)

My table displays product files, with the option to add notes. If a note is added, it shows in a row. If not, a text area field with a submit button appears instead.

Everything seems to be working well, except for the first row without a note. After adding a note and clicking the submit button, nothing happens.

HTML:

<div id="files-list" style="display: none">
        <table class="table">
            <thead>
                <tr>
                    <th>File</th>
                    <th>Date</th>
                    <th>Notes</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <c:if test="${fn:length(bean.product.files)>0}"> 
                <c:forEach items="${bean.product.files}" var="na">
                    <tr>
                        <td><a href="${pageContext.request.contextPath}/products/files/${na.id}.do">${na.name}</a></td>
                        <td><fmt:formatDate value="${na.created}" pattern="yyyy-MM-dd HH:mm" /></td>
                        <td>
                            <c:if test="${empty na.note}">
                                <form:form id="${na.id}" method= "POST" modelAttribute="bean" action="${pageContext.request.contextPath}/app/updateFile.ajax?id=${bean.product.id}&fileId=${na.id}" style="display: inline">                             
                                    <form:textarea path="prodFiles" rows="1" cols="50" />
                                    <input type="hidden" name="version" value="${bean.product.version}">
                                    <input type="submit" id="submitButton" value="Save it!" />
                                </form:form>    
                            </c:if>
                            <c:if test="${not empty na.note}">
                                <div style="max-width: 400px">${na.note}</div>                          
                            </c:if>
                        </td>
                        <td><button type="button" class="btn btn-xs btn-danger" onclick="$().mkdelformTable('${pageContext.request.contextPath}/app/deleteFile.ajax?id=${bean.product.id}&fileId=${na.id}', this)">Delete it!</button></td>
                    </tr>
              </c:forEach>
             </c:if>
           </tbody>
        </table>
    </div>

Possible insights:

  1. Upon opening the table (as a pop-up), the console indicates multiple
    [DOM] Found X elements with non-unique id
    errors
  2. Inspecting elements in developer tools revealed that the first row lacks the form part, which might be related to the issue of duplicated IDs. Example:
<td>                                                                
   <textarea id="prodFiles" name="prodFiles" rows="1" cols="50"></textarea>
   <input type="hidden" name="version" value="181">
   <input type="submit" id="submitButton" value="Save it!">
</td>

VS

<td>                            
   <form id="65" style="display: inline" action="/oferty/app/updateFile.ajax?id=12701&amp;fileId=65" method="POST">                             
      <textarea id="prodFiles" name="prodFiles" rows="1" cols="50"></textarea>
      <input type="hidden" name="version" value="181">
      <input type="submit" id="submitButton" value="Save it!">
   </form>  
</td>


Edit: Keep in mind that new files can always be added, so hard-coding different names or IDs is not a viable solution if suggested.

Answer №1

After discovering some legacy code, I successfully resolved issues related to 'multiple same ids' by implementing a pop-up notification on the previous page instead of using an input field. Additionally, I replaced it with a button that directs users to the new pop-up.

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

What is the best way to apply typography theme defaults to standard tags using Material-UI?

After reading the documentation on https://material-ui.com/style/typography/ and loading the Roboto font, I expected a simple component like this: const theme = createMuiTheme(); const App = () => { return ( <MuiThemeProvider theme={theme}> ...

The issue of stuttering arises in Safari when using a combination of size and translate transitions

When applying transitions to an element and adjusting the width and/or height along with -webkit-transform:translate3d, there is a noticeable stutter in the transition animation. It seems like the width/height change is animated first, then partially trans ...

Using percentages for CSS alignment and adjusting element widths

Greetings everyone! I have been struggling to align two divs - one on the right with a width of 30% and the other on the left with 70%. Despite my efforts, I have not been able to find a solution. I am hopeful that someone here can assist me. My setup inv ...

Is there a way to switch an input's appearance to resemble that of a label?

Looking to customize my input fields to resemble labels at first, then apply editable styles with angular.js upon button click. Utilizing bootstrap for my project, wondering if there is a built-in class that can be toggled on and off for these inputs? ...

Troubleshooting: WordPress failing to launch Bootstrap Modal

I recently transformed my PHP website into a WordPress theme, but unfortunately, I am facing an issue with my Bootstrap modal not opening in WordPress. ***Header.php*** <a id="modal_trigger" href="#modal" class="sign-in-up"><i class="fa fa-user ...

What is the best way to display tip boxes for content that is added dynamically?

One of the challenges with my web page is that dynamically added content does not display tipboxes, unlike items present since the page load. I utilize the tipbox tool available at http://code.google.com/p/jquery-tipbox/downloads/list. To illustrate the i ...

Any tips on creating a website with a gradient background that moves along with the window as you scroll?

Can anyone help me figure out how to achieve this? I'm trying to create a similar effect to the one on the fireship website, but I'm having trouble replicating it. Appreciate any guidance. Thanks! ...

What are the risks of using a PHP file within an iframe?

Upon discovering that my web server was unable to run PHP within my HTML file, I decided to use an iframe directed to my PHP script instead. The implementation went smoothly, and now my website features a charming comment form for users to interact with. ...

Can a fixed div be made to adapt to different screen sizes?

Struggling to make SVG data charts responsive due to the 'position:fixed' CSS attribute applied, I'm exploring alternative solutions that don't involve media queries. Ideally, I want the SVG to scale up and down while remaining centered ...

Efficient Techniques for Deleting Rows in a Dynamic JavaScript Table

I'm facing an issue where I want to remove each line added by the user, one by one. However, my current program is removing all the rows from the table instead of just one at a time. The objective is to allow the user to remove a specific row if they ...

Utilizing various z-index values for multiple background images in a single CSS class

My approach may be completely off. I am in the process of building a website using sliced images from a .PSD file created by a graphic artist. Essentially, the background image consists of 4 green bars angled at 45 degrees slightly intertwined with 3 blue ...

Unable to view Bootstrap modal upon click

Whenever I attempt to display a modal using Bootstrap, it mysteriously appears upon page refresh but fails to show up when the button is clicked. Ideally, I want the modal to only appear when the user clicks on the button. The structure of my html file lo ...

Resetting form fields when clicking the "Next" button with the FormToWizard jQuery Plugin

I am in the process of developing a lengthy form using the jQuery plugin called formToWizard. Within one of the fieldsets located midway through the form, there are hidden fields that are displayed upon clicking a button. The strange issue I am encounterin ...

Problem with Ajax causing full-page reload

I currently have a webpage that utilizes JqueryUI-Mobile (specifically listview) in conjunction with PHP and some Ajax code. When the page loads initially, it displays a list generated from a MySQL DB. I want this list to refresh itself periodically witho ...

Javascript postback functionality is fully operational in bootstrap 4, however, it is failing to return

Encountering an issue with my postback JavaScript function in the ASP/BootStrap environment. After searching on stackoverflow for a solution, I couldn't find one that resolved my problem. The problem is when I click on an image, the page reloads (the ...

Unable to load variables into site.css in order for Flask app to successfully render home.html

I'm encountering difficulties in getting my site.css file to accept two variables passed in from my app.py using Jinja2 templates, namely {{ variable }}. In app.py, I have defined two variables named empty_fill_line and fill_line, which dynamically up ...

Tips for implementing styling in a material table within a reactjs application

Is there a different way to set the display property to inline-block since cellStyle doesn't seem to recognize it? How can I adjust the width of a specific column, let's say with the name title, without affecting the width of all other co ...

How can I align the middle of the element within its parent until it hits the top-left edge, at which point should I stop center

I am trying to center an element within a parent container. It seems simple with methods like transform, flexbox, and grid... The issue arises with overflow behavior. When the parent container shrinks below the dimensions of the child element, scrollbars a ...

Prevent selection of future dates in HTML input using PHP exclusively

I am looking for a way to limit the date input on my form using PHP and HTML. <?php echo '<input type="date" name="doc" value="' . date("d-m-Y") . '" min="11-05-2014" max="' . date("d-m-Y") . '"/>'; ?> While rese ...

What is the best way to include an icon in a Vue child component?

Struggling to implement the image in the template using both the img tag and as a background. Despite having the correct path to the icon, neither method seems to work. Check out the code snippet here <div> <a href="#" class="icon" > ...