Computer Science, asked by akankshaprasad25, 10 months ago

SOP 1: Create JavaScript program for the following using appropriate variables,
JavaScript inbuilt functions and control structures.
. To accept integer and display the result by multiplying it with 3.
. To accept two integers and display larger number of them.
. To check whether, user entered number is positive or negative.​

Answers

Answered by migana
16

Answer:

read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.

Questions Jobs Tags Users Badges Ask

up vote

7

down vote

favorite

Individual error messages for empty form fields using JavaScript

javascript html forms validation

I need to validate my form using JavaScript because iPhone / Safari do not recognize the required attribute. I want individual error messages to appear below each empty input field.

My code works, but the individual error message does not disappear when the field is filled in. Also, I would like all messages to appear initially, for all empty fields (not one by one). I am very very new to JavaScript, sorry.

My HTML:

<form onsubmit="return validateForm()" method="post" action="form.php" name="english_registration_form" id="english_registration_form">

<input type="text" id="name" name="name" aria-describedby="name-format" required placeholder="Name">

<span class="error"><p id="name_error"></p></span>

<input type="email" id="email" name="email" required placeholder="Email">

<span class="error"><p id="email_error"></p></span>

<input type="tel" id="telephone" name="telephone" required placeholder="Telephone">

<span class="error"><p id="telephone_error"></p></span>

<button class="register_button" type="submit" value="submit">Register Now</button>

</form>

And my JavaScript:

<script>

function validateForm() {

var x = document.forms["english_registration_form"]["name"].value;

var y = document.forms["english_registration_form"]["email"].value;

var z = document.forms["english_registration_form"]["telephone"].value;

if (x == null || x == "") {

nameError = "Please enter your name";

document.getElementById("name_error").innerHTML = nameError;

return false;

}

else if (y == null || y == "") {

emailError = "Please enter your email";

document.getElementById("email_error").innerHTML = emailError;

return false;

}

else if (z == null || z == "") {

telephoneError = "Please enter your telephone";

document.getElementById("telephone_error").innerHTML = telephoneError;

return false;

}

else {return true;}

}

</script>

Thanks for your help.

Answered by abhidnya422
0

Explanation:

hshsjsjskskdjshsbbsjsjs

Attachments:
Similar questions