Question

How do you stop web form data from being submitted to the server, if it is...

How do you stop web form data from being submitted to the server, if it is determined by a JavaScipt function, that the data is not valid? You can give an example.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

You can use the return value of the function to prevent the form submission

An example of the script would be:

<script type="text/javascript">
function validateMyForm()
{
  if(check if your conditions are not satisfying)
  { 
    alert("validation failed false");
    returnToPreviousPage();
    return false;
  }

  alert("validations passed");
  return true;
}
</script>

and it would look like this in your HTML page:

 <form onsubmit="event.preventDefault(); validateMyForm();">
Add a comment
Answer #2

HTML form validation is done using JavaScript, which prevents the data from being submitted to the server if it is not valid.
If the form field is empty or it does not contain the required data, the Javascript function returns false or alert message.

Below is the sample web form where validation is applied using the JavaScript-

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript for Validation</h2>

<p>Please input a number between 1 and 20:</p>

<input id="numb">

<button type="button" onclick="myFunction()">Submit</button>

<p id="demo"></p>

<script>
function myFunction() {
var x, text;

// Get the value of the input field by it id
x = document.getElementById("numb").value;

// If the input (x) is Not a Number or less than one or greater than 20
if (isNaN(x) || x < 1 || x > 20) {
text = "Input not valid";
} else {
text = "Input OK";
}
document.getElementById("demo").innerHTML = text;
}
</script>

</body>
</html>

Sample Output-

Add a comment
Know the answer?
Add Answer to:
How do you stop web form data from being submitted to the server, if it is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How do you stop web form data from being submitted to the server, if it is determined by a JavaSc...

    How do you stop web form data from being submitted to the server, if it is determined by a JavaScipt function, that the data is not valid? You can give an example.

  • I do not know what web server is being used. All I have is the question...

    I do not know what web server is being used. All I have is the question displayed. If I had to guess, IIS is the web server. A credentialed scan has discovered a potential information disclosure vulnerability on a web server. A security administrator reviews the following associated logs to determine the validity of the result Web Server Logs 192.168.1.10 - GET././C/Users\Administrator Documents Server pfx HTTP/1.0" - 200 DLP Logs PERMIT 192.168.1.10 Serverpfx Which of the following should the administrator...

  • Project Description In this project, you will be developing a multithreaded Web server and a simple...

    Project Description In this project, you will be developing a multithreaded Web server and a simple web client. The Web server and Web client communicate using a text-based protocol called HTTP (Hypertext Transfer Protocol). Requirements for the Web server The server is able to handle multiple requests concurrently. This means the implementation is multithreaded. In the main thread, the server listens to a specified port, e.g., 8080. Upon receiving an HTTP request, the server sets up a TCP connection to...

  • Hi I'm trying to write a code for a web server in python with flask. This...

    Hi I'm trying to write a code for a web server in python with flask. This is what I have so far from flask import Flask app = Flask(__name__) @app.route('/') #first endpoint i.e. "http://localhost/" def index(): return 'hello' #return data in string if __name__ == '__main__': app.run(debug=True) After running the code, I'm given a address to the web with the text hello. The problem is that this only works with my computer that is running the code. If I try...

  • help! Due: 10/31/17 Submit under: Assignmen8 folder (only) Chapter-10: Apache Web Server Explain that a web...

    help! Due: 10/31/17 Submit under: Assignmen8 folder (only) Chapter-10: Apache Web Server Explain that a web server is a network computer with the primary role of serving Web pages to clients on request. 1、 2. Explain that the HTTP-Server is a YaST module for configuring Apache. The package name is yast2-http-server, and it can be installed from YaST Software Management. Discuss the following default settings for a Web server in Apache: " DocumentRoot . Alias . ScriptAlias . Include ....

  • 1. You have a web server running on port 8888 in a Linux computer, but without...

    1. You have a web server running on port 8888 in a Linux computer, but without any firewall rules in place for protection. Now, you want to use iptables to protect the website so that only computers from address 172.90.0.0/16 but excluding 172.90.255.0/24 can access the web server. Show the commands of iptables that add the Linux firewall rules to enforce the protection.

  • Consider a home network consisting of a router, a Web server hosting your own website, and...

    Consider a home network consisting of a router, a Web server hosting your own website, and 4 different wireless devices. Suppose that all nodes on the home network are addressable/reachable by their IPs only. Answer the following: a) How does your router get assigned its IP? What is the nature of such IP (e.g., static vs dynamic, global vs local, public vs private)? b) How do the different wireless devices get assigned their IPs? What is the nature of such...

  • How do you determine the credibility of information you get from the web? How would you...

    How do you determine the credibility of information you get from the web? How would you rank the reliability of information provided by each of the following sources of Web pages? Does the type of information you're seeking affect your ranking? Established newspaper Counterculture newspaper Television network Corporation Nonprofit organization Individual How do you determine the credibility of information you get from the web? How would you rank the reliability of information provided by each of the following sources of...

  • In 500 words or less describe with your own words the steps included in a Web session. You can us...

    In 500 words or less describe with your own words the steps included in a Web session. You can use an example describing the internal steps in the system from the moment a person wishes to visit a website to the moment the website information is displayed on the computer screen for the user. You may use a point-form numbered list to describe each step of the process. Make sure to describe concepts such as: Web Browser, URL, Doman name,...

  • Create a web form to display the data from the database. Add the capability to insert,...

    Create a web form to display the data from the database. Add the capability to insert, update and delete data create your own form for data manipulation with buttons

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT