Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

99
Visualizações
Script tag not printing any message

In the given code , I am trying to print the message but after taking input its not printing any message.

<!DOCTYPE html>
    <html>
        <head>
            <title>CSS</title>
        </head>
        <body>
            <form onsubmit="return Ak()">
                <input type="text" name="abinash" placeholder="abinash"  required id="q"><br><br>
                <input type="submit" name="submit" value="submit">
                <div id="w"></div>
            </form>
            
            <script type="text/javascript">
                function Ak()
                {
                    var y=document.getElementById("q").value;
                    document.getElementById("w").innerHTML="You have typed this password"+y;
                    
                 
                }
            </script>
        </body>
    </html>

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

It was working, but after submitting form, all of content disappeared. You need to add event.preventDefault(); to onsubmit attribute of form:

<!DOCTYPE html>
    <html>
        <head>
            <title>CSS</title>
        </head>
        <body>
            <form onsubmit="event.preventDefault(); return Ak()">
                <input type="text" name="abinash" placeholder="abinash"  required id="q"><br><br>
                <input type="submit" name="submit" value="submit">
                <div id="w"></div>
            </form>
            
            <script type="text/javascript">
                function Ak()
                {
                    var y=document.getElementById("q").value;
                    document.getElementById("w").innerHTML="You have typed this password"+y;
                    
                 
                }
            </script>
        </body>
    </html>

about 4 years ago · Juan Pablo Isaza Relatório

0

Pressing the submit button will refresh the page. event.preventDefault(); use this keyword.

 <script type="text/javascript">
        function Ak()
        {
            var y=document.getElementById("q").value;
            document.getElementById("w").innerHTML="You have typed this password"+y;
            event.preventDefault();

        }
    </script>
about 4 years ago · Juan Pablo Isaza Relatório

0

event.preventDefault()

It is working, it's just that when you click that submit button the page reloads. I tried it out, and you can fix it by adding e.preventDefault(); to your function, and put (e) as the arg in the function, like so:

<!DOCTYPE html>
    <html>
        <head>
            <title>CSS</title>
        </head>
        <body>
            <form onsubmit="event.preventDefault(); return Ak()">
                <input type="text" name="abinash" placeholder="abinash"  required id="q"><br><br>
                <input type="submit" name="submit" value="submit">
                <div id="w"></div>
            </form>
            
            <script type="text/javascript">
                function Ak()
                {
                    var y=document.getElementById("q").value;
                    document.getElementById("w").innerHTML="You have typed this password: "+y;
                    
                 
                }
            </script>
        </body>
    </html>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda