Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7900299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:56:08+00:00 2026-06-03T08:56:08+00:00

I have the following html code for my php page. <span id=edit_button_<?php echo $row[$id];

  • 0

I have the following html code for my php page.

<span id="edit_button_<?php echo $row[$id]; ?>" style="display:block;" onClick="editRow(this, '');"><img src="images/edit.png" />
<span id="edit_save_<?php echo $row[$id]; ?>" style="display:none;" onClick="saveRow(this,'');"><img src="images/green_check.png" />
<span id="edit_cancel_<?php echo $row[$id]; ?>" style="display:none;" onClick="cancelEdit(this, '');"><img src="images/red_cross.png" />

In the editRow() function, I added the following lines to make the #edit_save_ and #edit_cancel_ elements visible:

$('#edit_save_'+id).show();
$('#edit_cancel_'+id).show();

But they are not getting displayed. I then added the following lines as well, but it didn’t work either:

document.getElementById('edit_save_'+releaseTable+relPid).style.display = 'block';
document.getElementById('edit_cancel_'+releaseTable+relPid).style.display = 'block';        

Strangely, the issue is only with some of the records. Like row 1 is showing green_check and red_cross images, but row 2 doesn’t.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:56:10+00:00Added an answer on June 3, 2026 at 8:56 am

    The reason the first row is working but the subsequent rows are not is because you can’t have multiple rows with the same IDs. Unlike jQuery class selectors, ID selectors will find the 1st match and only that match, which in your case is that first row.

    Also, it is preferable not to have your JavaScript inline with your HTML. This is what people call “separation of concerns” or “separation of presentation and logic” or any permutations of that. It is best to put the Javascript within a <script> tag either on the same page as your PHP or preferably as an external script.

    so instead of this inline function call:

    <span onclick="editRow()"></span>
    

    you would do this:

    <script>
          $('span').on('click', function(){
               //call editRow(); 
               // or make other javascript which performs editRow function (toggle display)
           });           
    </script>
    

    To get back to your scenario and overcome this issue with using an ID-based selector, add a class to each clickable button, edit_button, like this:

    HTML:

    <span class="edit_button" data-id="<?php echo $row[$id]; ?>" id="edit_button_<?php echo $row[$id]; ?>" style="display:block;" ><img src="images/edit.png" /></span>
    <span id="edit_save_<?php echo $row[$id]; ?>" style="display:none;" onClick="saveRow(this,'');"><img src="images/green_check.png" /></span>
    <span id="edit_cancel_<?php echo $row[$id]; ?>" class="cancel_button" data-id="<?php echo $row[$id]; ?>" style="display:none;" ><img src="images/red_cross.png" /></span>
    

    this is then what the JS looks like:

    $('.edit_button').on('click', function(){
        var id=$(this).data('id');
        $(this).toggle();
        $('#edit_save_'+id).toggle();
        $('#edit_cancel_'+id).toggle(); 
    });
    
    $('.cancel_button').on('click', function(){
        var id=$(this).data('id');
        $(this).toggle();
        $('#edit_save_'+id).toggle();
        $('#edit_button_'+id).toggle(); 
    });
    

    Please see this JSfiddle where I’ve taken the PHP out of it. I believe it shows the behavior that you’re interested in: http://jsfiddle.net/trpeters1/vLMCh/14/

    Lastly, please add closing </span> tags.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following HTML page: <div id=foobar> <?php echo $dynamicVar; ?> </div> <input
I have the following code: <?php if ($x == 1){ ?> <b>Some html...</b> <?php
I have the following html code. <html> <body> <div style=max-width:1600px; min-width:900px; > <table> </table>
I have the following HTML Code <%@ Page Language=C# %> <html> <head> <title></title> </head>
I have the following html code: <table> <tr> <td> <div id=fixmywidth style=position:relative; height:30px;> <div
I have the following html / Javascript: http://pastie.org/782618 And the following Zend PHP Code
I am facing a strange problem. My PHP page has following code. echo <div
I have the following html code (in the given order) <div id=content>...</div> <div id=footer>...</div>
I have the following HTML code based on a tab menu format, i.e: <div
I have the following html code: <mytag> Just Some Text </mytag> And I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.