Update the page when the Cancel prompt is selected

Issue:

I am facing a problem with my web page. After entering data and clicking save, a confirmation pop-up appears. If I choose to cancel, I want the page to refresh so that the entered data is cleared.

Below is the current code for the confirmation process:

function checknumber() {
    var x = document.getElementById('<%=view_txt_pixelwidth.ClientID%>').value;
    var y = document.getElementById('<%=view_txt_pixelheight.ClientID%>').value;
    var z = document.getElementById('<%=view_txt_printleft.ClientID%>').value;
    var a = document.getElementById('<%=view_txt_printtop.ClientID%>').value;
    var b = document.getElementById('<%=view_txt_printwidth.ClientID%>').value;
    var c = document.getElementById('<%=view_txt_printheight.ClientID%>').value;                       

    var anum = /(^\d+$)|(^\d+\.\d+$)/
    if ((anum.test(x)) && (anum.test(y)) && (anum.test(z)) && (anum.test(a)) && (anum.test(b)) && (anum.test(c)))
        testresult = confirm('Do you want to save changes?');
    else {
        alert("Please input a valid number!")
        testresult = false
    }
    return (testresult);
}                        

function Validate_view() {
    var value = document.getElementById('<%=view_txt_name.ClientID%>').value;
    var value2 = document.getElementById('<%=view_txt_title.ClientID%>').value;
    var value3 = document.getElementById('<%=view_txt_description.ClientID%>').value;
    var value4 = document.getElementById('<%=view_txt_pixelwidth.ClientID%>').value;
    var value5 = document.getElementById('<%=view_txt_pixelheight.ClientID%>').value;
    if (value == '' || value2 == '' || value3 == '' || value4 == '' || value5 == '') {
        ValidatorEnable(document.getElementById('<%= view_req_pixelwidth.ClientID %>'), true);
        ValidatorEnable(document.getElementById('<%= view_req_pixelheight.ClientID %>'), true);
        ValidatorEnable(document.getElementById('<%= view_req_name.ClientID %>'), true);
        ValidatorEnable(document.getElementById('<%= view_req_title.ClientID %>'), true);
        ValidatorEnable(document.getElementById('<%= view_req_description.ClientID %>'), true);
    }
    if (value == '' || value2 == '' || value3 == '' || value4 == '' || value5 == '') {
        alert("Please enter the missing fields");
        return false;
    }
    else if (document.layers || document.all || document.getElementById) {
        return checknumber();                            
    }

    <asp:Button ID="view_btn_save" Text="Save" OnClick="view_btn_save_click"
    OnClientClick="return Validate_view(); "
}

Answer №1

if ((anum.test(x)) && (anum.test(y)) && (anum.test(z)) && (anum.test(a)) && (anum.test(b)) && (anum.test(c)))
    testresult = confirm('do you want to save your changes?');
    if(testresult == 0)
    {
        //canceled
        //window.location.reload(true);
        window.location.href=window.location.href;
    }
else {
   alert("Please enter a valid number!")
   testresult = false
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The video continues playing even after closing the modal box

I am facing an issue with my code where a video continues to play in the background even after I close the modal. Here is the code snippet: <div class="modal fade" id="videoModal" tabindex="-1" role="dialog" aria- ...

Having trouble with the form parsing not functioning properly

I have been utilizing Express.js along with the body-parser module for form parsing on the server. However, I am facing an issue where the content received appears as an empty object under res.body. This is how my app.js looks: var express = require("exp ...

What could be the reason for the esm loader not recognizing my import?

Running a small express server and encountering an issue in my bin/www.ts where I import my app.ts file like so: import app from '../app'; After building the project into JavaScript using: tsc --project ./ and running it with nodemon ./build/bin ...

Implement an onClick event to the newly created th element using document.createElement()

Through the use of document.createElement("th"), I am dynamically inserting columns into a table. var newTH = document.createElement('th'); Is there a way to add an onClick attribute to this element so that users can delete a column by clicking ...

Is it possible to utilize a variable while assigning an element id through a JavaScript function?

Currently, I am in the process of learning JavaScript and have come across a scenario that has left me uncertain. I am attempting to utilize a variable in a particular situation and am unsure if it will work as expected. I am looking to assign a unique id ...

Angular protection filter

Every time I used Angular CLI to generate a new component, it would create the component with standard parameters: @Component({ selector: 'app-test1', templateUrl: './test1.component.html', styleUrls: ['./test1.component.css ...

Nuxt.js is throwing a TypeError because it is unable to access the 'minify' property since it is undefined

When I try to generate a Nuxt app using "npm run generate" or "npm run build", I encounter an issue where it throws a TypeError: Cannot read property 'minify' of undefined. Does anyone know how to solve this? TypeError: Cannot read property &apo ...

Converting HTML/Javascript codes for Android Application use in Eclipse: A Step-by-Step Guide

How can I implement this in Java? Here is the HTML: <head> <title>Google Maps JavaScript API v3 Example: Geocoding Simple</title> <link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="styles ...

Tips for incorporating environment variables within a node configuration file

Assuming I have an environment variable $KEY Currently, I am executing KEY=$KEY babel-node build.js //using webpack to create a bundle of my code An issue arises in the JavaScript files bundled by webpack due to an import statement pointing to config.j ...

Embed a static label inside an input field that remains constant even while text is inputted, without using a placeholder. Crafted using HTML,

Take a look at the screenshot below - what you see on the left side is my current setup, while on the right side is the desired outcome achieved without any plugins or HTML5 attributes The left side scenario occurs when I have 2 input fields - one with th ...

Is there a way I can retrieve my Nodemailer email and store it in a variable?

I am currently utilizing the nodemailer module in conjunction with node.js and have successfully implemented the following: let transporter = nodemailer.createTransport({ service: 'gmail', auth: { user: '<a href="/cdn-cgi/l/email ...

I'm puzzled as to why I am getting undefined values for both the selected image file and the image title (not the filename) when sending a request to my API

I need help with my front end code that allows users to upload an image file along with a title input. The API works fine on postman, but the user-inputted values for the image and title are not being pulled correctly on the frontend side. I keep getting & ...

Tips for concealing labels until the submit button is activated

I am currently handling a project involving a Spring Controller and JSP. Within a JSP page, I have included a button labeled Process. Upon clicking this button, two radio buttons are displayed below it along with a Submit button. After tapping the Submit ...

Navigating to a specific div on a view using ASP.NET MVC5 routing

I am currently facing an issue while setting up a route that needs to route to a specific div on a page in my RouteConfig.cs file. However, every time I try to do so, I encounter an HTTP Error 403.14 - Forbidden message. routes.MapRoute( name: " ...

I am looking to incorporate a new "ID" column into my mui data grid table in ReactJS that will incrementally count from 0 to the total number of rows

When displaying data from an API in a datagrid table component with multiple columns, it is necessary to include a column for the ID which should have values ranging from 0 to the number of rows. Currently, the Object_id is being displayed in this cell. T ...

Adjust the HTML markup based on the content within RenderBody()

Within my _Layout.cshtml file: <section class="container content-section text-center"> @RenderBody() </section> I have a specific requirement where I only want the "section" element to be present if the current page is ...

Utilizing an Angular foreach loop for restructuring JSON data

I currently have an ng-repeat function that outputs arrays of objects in the following format: [ {"day":"10","title":"day","summary":"summary","description":"ok","_id":"53f25185bffedb83d8348b22"}, {"day":"3","title":"day","summary":"summary","description" ...

page.isValid compared to this.isValid

What distinguishes the use of This.IsValid from Page.IsValid? ...

Is the Vue "Unchecking" feature not properly deleting data from the array?

I need to update my function to handle the removal of a networkAudience when its corresponding checkbox is unchecked. Currently, the networkAudience is being added to the array when checked, but not removed when unchecked. What changes should I make to en ...

Issue encountered when submitting form: Error identified as "Unexpected string expression without template curly in string"

As a novice in React.js, I am facing an issue where setState is not functioning properly when submitting a form. Any suggestions on how to resolve this problem? > class Home extends Component{ constructor(props){ > super(props) > ...