Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!