vendredi 3 septembre 2021

How can i write a script to show the password?

i don't really know how i could get the checkbox to show the password next to it.could you help me with that? I tried it really hard but i can't do it. Could you offer me a book or link to learn it? So my problem is i can't send a html object name to a javascript which one i selected . i don't really know how i could get the checkbox to show the password next to it.could you help me with that? I tried it really hard but i can't do it. Could you offer me a book or link to learn it? So my problem is i can't send a html object name to a javascript which one i selected.

<form action="" method="post">
  <table>
    <tr>
      <td>Felhasználónév:</td>
      <td><input value="" type="text" id="user" name="user" required /></td>
    </tr>
    <tr>
      <td>Jelszó:</td>
      <td><input value="" type="password" name="password" id="password" required><br><br>
    </tr>
    <tr>
      <td>Leírás:</td>
      <td><input value="" type="text" id="leiras" name="leiras" /></td>
    </tr>
    <tr>
      <td colspan="2"><input type="submit" name="submit" id="submit" value="Add" /></td>
      <td> <input type="checkbox" onclick="showPassword()"> Show Password </td>
    </tr>
  </table>
</form>
 
<?php
  if(isset($_POST['submit']))
  {
    hozzaad();
  }
  
  function hozzaad()
  { 
    $felhasznalo = $_POST['user'];
    $jelszo = $_POST['password'];
    $leiras = $_POST['leiras'];
    $parancs = "INSERT INTO `jelszavak`(`user`, `jelszo`, `leiras`) VALUES ('$felhasznalo','$jelszo','$leiras')";
    adatbazis($parancs);
    kiirat();
  }
  
  function kiirat()
  {
    $parancs = "select * from jelszavak";
    $result = adatbazis($parancs);
    echo "<!DOCTYPE html>
      <html>
      <body>
      <form>
        <table>
    ";
    $azonosito = 0;
    
    foreach($result as $row)
    {
      echo "
        <tr>
           <td> Felhasználónév: <input value='$row[user]' type='text' name='user' id='user'> </td>
           <td> Jelszó:<input value='$row[jelszo]' type='password' name='jelszo$azonosito.' id='jelszo'> </td>
           <td>  <input type='checkbox' onclick='showPassword()'>  Show </td> 
           <td>  Leírás:<input value='$row[leiras]' type='text' name='leiras' id='leiras'> </td>
        </tr>
      ";
      $azonosito++;
    }
    
    echo "
      </table>
    </form>
    </body>
    </html>
//code should be here
    <script>
      function showPassword() {
        var passwordType = document.getElementById('jelszo1');
        if (passwordType.type === 'password') {
        passwordType.type = 'text';
        } else {
        passwordType.type = 'password';
        }
      }
    </script>
    ";
  }
  
  function adatbazis($parancs)
  {
    require_once('adatbazis.php');
    $obj1= new adatbazis();
    $db = $obj1->database();
    return $result = $obj1->lekerdezes($parancs,$db);
  }
?>

//or here?
<script>
  function showPassword() {
    var passwordType = document.getElementById('jelszo1');
    if (passwordType.type === 'password') {
      passwordType.type = 'text';
    } else {
      passwordType.type = 'password';
    }
  }
</script>



Aucun commentaire:

Enregistrer un commentaire