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

  • SEARCH
  • Home
  • 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 3486366
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:01:18+00:00 2026-05-18T11:01:18+00:00

i have a javascript function who’s task is to show the hidden rows of

  • 0

i have a javascript function who’s task is to show the hidden rows of a table
javascript function:

function blabla(count){
 count++;  var id="ph"+count; 
 document.getElementById(id).style.display=""; 
}

Then i have a table in the same document with a button on the 1st row which triggers onclick event:

<script to declare globale variable count=1/>
<table>
 <tr id="ph1"><td>haha:<button onClick="blabla(count)"><button></td></tr>
 <tr id="ph2" style="display:none"><td>hoho</td></tr>
 <tr id="ph3" style="display:none"><td>hihi</td></tr>
</table>

when the page is loaded and i click on the button one time:the second row is shown..but when i click on it the second time..the third row is Not displayed…
Why is that?
anyone can help me out?

  • 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-05-18T11:01:18+00:00Added an answer on May 18, 2026 at 11:01 am

    It’s because the variable “count” disappears as soon as the function call ends, so you end up showing the same table row every time. You could try moving the variable to global scope:

    var count = 1;
    function blabla() {
        count++;
        var id="ph"+count;
        document.getElementById(id).style.display="";
    }
    

    Based on your html, you could then change it like this:

    <table> 
        <tr id="ph1">
            <td>haha:</td>
            <td><input type="file" id="w"/></td>
            <td><img src="Style/Images/plus.jpg" onClick="blabla()"/></td>
        </tr> 
        <tr id="ph2" style="display:none">
            <td>hoho:</td>
            <td><input type="file" id="1"/></td>
        </tr> 
        <tr id="ph3" style="display:none">
            <td>hihi:</td>
            <td><input type="file" id="2"/></td>
        </tr> 
    </table>
    

    So, just remove the count from the function call.

    However, you will encounter an error when you keep pressing the button (when you run out of elements with ids starting with “ph”). If you don’t want this to happen, do something like this:

    var count = 2;
    function blabla() {
        var element = document.getElementById("ph" + count);
        if (!element) {
            alert('No more rows!');
        } else {
            element.style.display = "";
            count++;
        }
    }
    

    Finally, this could be done more robustly using something like jQuery, but I try to stay as close to your original code as possible.

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

Sidebar

Related Questions

So I have the following JavaScript code: <script type=text/javascript> function clearRadioButtons() { document.getElementById(radiobutton1).checked=; //etc
I have an external JavaScript that contains: function random_imglink(){ var myimages=new Array() myimages[1]="http://sevir.sitegoz.com/jchs/Banner1.png" myimages[2]="http://sevir.sitegoz.com/jchs/banner2.png"
I have a javascript function that manipulates the DOM when it is called (adds
We have a JavaScript function named move which does just windows.location.href = any given
I have a JavaScript function, pop_item . I have to call this from PHP,
I have a javascript function (class) that takes a function reference as one paremter.
I have a javascript function (function1) that checks some global variables (can the user
I have a little javascript function which is attached to an onClick event of
I have Designed the Javascript function My.js it contains following code My.js function display(){
I want to call a c# function from my javascript function. I have a

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.