0

Was adding tab names and class name from the database took care of dots hyphens but couldn't debug please help new to this.

  <?PHP

        $result = $conn->query("select hyd_name,hyd_classname from hydro_department"); 
        while ($row = $result->fetch_assoc()) 
        {
        unset($hmr_id);
        $hyd_name = $row['hyd_name'];
        $hyd_classname=$row['hyd_classname'];
        echo '<button class="tablinks" onclick="openTab(event,"'.$hyd_classname.'")">'.$hyd_name.'</button>';
        }
    ?>

Here is my JS

function openTab(evt, tabName) {
  // Declare all variables
  var i, tabcontent, tablinks;

  // Get all elements with class="tabcontent" and hide them
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }

  // Get all elements with class="tablinks" and remove the class "active"
  tablinks = document.getElementsByClassName("tablinks");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
  }

  // Show the current tab, and add an "active" class to the button that opened the tab
  document.getElementById(tabName).style.display = "block";

  evt.currentTarget.className += " active";
}
Saad Ghojaria
  • 41
  • 1
  • 8
  • 1
    You don't need the double quotes here: `"'.$hyd_classname.'"`. Basically, when you added them, you ended the `onclick` too early (`onclick="openTab(event,"` <-- this was interpreted as the end of the attribute). – El_Vanja Dec 07 '20 at 12:00
  • echo ""; I tried this but same problem – Saad Ghojaria Dec 11 '20 at 06:13
  • 1
    I suggest you go through a tutorial about strings. You can start [here](https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php). You ended the `onclick` early *again*, just in a different syntax (`onclick='openTab(event,'` <-- same error, but with different quotes). I also advise you to take a look at the page source, you will see that you generated a scrambled HTML. – El_Vanja Dec 11 '20 at 08:25
  • This worked fine for me query("select hyd_name,hyd_classname from hydro_department"); while ($row = $result->fetch_assoc()) { unset($hmr_id); $hyd_name = $row['hyd_name']; $hyd_classname=$row['hyd_classname']; echo (""); } ?> – Saad Ghojaria Dec 13 '20 at 18:52

0 Answers0