1

so what I try is to show an error "First name must be filled out" as a text called "check", not as an alert... Please help:)

  <html>
  <body>

 <form name="myForm" action="page.html" onsubmit="return validateForm()" method="post">
  First name: <input type="text" name="box>
 <input type="submit" value="Submit">
</form> 
<p id="check"></p>


<script>

function validateForm() {
var x = document.forms["myForm"]["box"].value;
if (x == null || x == "") {
    alert("First name must be filled out") ="check"; // I tried to send alert as text... 
    return false;
 }
 } 

  </script>

  </body>
   </html> 

Thanks in advance!

2 Answers 2

3

Change

alert("First name must be filled out") ="check";

to

document.getElementById('check').innerHTML = 'First name must be filled out';
Sign up to request clarification or add additional context in comments.

Comments

2

As pure Javascript Solution you could replace the alert with the following code:

document.getElementById('check').innerHTML = "First name must be filled out";


In jQuery you could try:

$( "#check" ).html( 'First name must be filled out' );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.