Suppress OnBlur Validation Alert On Window Close

Dec 10, 2009

Using Javascript, ASP.net with C# code behind. I am validating a textbox using the onblur event. It is being validated in that it must have an alphanumeric entry before the user tabs off of it to the next box. The validation part works, the part that doesn't work is that I get the validation alert textbox if I close the window. I have a workaround in that I am assigning that textbox a character using windo.onberforeunload but I know that isn't right.

Here is what I have so far...
Code behind on Page_Load...
txtCLBRTNWC.Attributes.Add("onblur", "return reqVLD(this)");

Here is my textbox field...
<asp:TextBox ID="txtCLBRTNWC" runat="server" Width="75" MaxLength="4"
ontextchanged="txtCLBRTNWC_TextChanged" TabIndex="1"
onkeyup="clbwclngCHK(this);" ></asp:TextBox>

And here are the 2 functions being used...
function reqVLD(alphanumericChar){
var chk = /^[a-zA-Z0-9]+$/;
// var boxid = document.getElementById("<%=txtCLBRTNWC.ClientID%>").value;
// var matchArray = boxid.match(chk);
if(document.getElementById("<%=txtCLBRTNWC.ClientID%>").value.match(chk)){
return true;
} else {
document.getElementById("<%=txtCLBRTNWC.ClientID%>").focus();
document.getElementById("<%=txtCLBRTNWC.ClientID%>").value = "";
alert("Please enter a Work Center.");
return false;
}}
function clbwclngCHK(obj_in)//When txtCLBRTNWC entry hits the max of 4 auto focuses to next box. {
if (obj_in.value.length == 4) document.getElementById("<%=txtSTRTDT.ClientID%>").focus();
}

Here is my work around...
window.onbeforeunload = function (){
document.getElementById("<%=txtCLBRTNWC.ClientID%>").value = "1";
}

User has to enter something in box before they can move on. This is checked and validating using an onblur event. Problem is, the onblur event fires if closingexiting the window.

View 9 Replies


ADVERTISEMENT

Display Alert When Close The Browser Window

Dec 24, 2009

I need to display alert when I close the browser window. Now I am using the following code to display the alert. But the alert is getting displayed even I click on any links. But the alert should not displayed when i click the link.

This is my code:

View 1 Replies View Related

Possible To Display Alert When Close Browser Window?

Dec 23, 2009

I need to display alert when I close the browser window. Now I am using the following code to display the alert. But the alert is getting displayed even I click on any links. But the alert should not displayed when i click the link. [code]...

View 6 Replies View Related

Top.close Closes The Window Before Responding To Alert In Child Frame

Dec 20, 2005

I am encountering a problem where I have a window and there are three
frames, one in the left, right and in the bottom. The bottom most frame has
common submit buttons. There are several tabs in left frame. Each one loads
a different form on the right frame. After fetching the contents of the form
from user, I am validating the text fields in the form using onChange() event
handler. After entering the text value in the textbox, if I press Submit
directly, the "Submit" as well as the validation routine happens concurrently.
Only at the end of validation, the field is marked as dirty. Now, if field is not
marked dirty, the Submit function will close the window without actually
submitting as nothing was changed. So when an invalid value is entered and
the Submit is pressed directly, an alert pops up temporarily but the close()
call from the parent frame immediately closes the alert window before user
can respond. This problem does not occur in IE as in IE, unless the alert
window is responded, the close() call cannot close the alert window. Code:

View 7 Replies View Related

OnBlur="window.close()" And MS IE 6

Jul 23, 2005

I've got a window with a "<body onBlur="window.close()"> tag that keeps closing prematurely. It happens when the user clicks on text inside a table in the same window. Apparently IE decides that the <body> no longer has the focus if the <table> within the <body> has it. Firefox handles the page correctly as does MS 5.

This may be one of those "security features" that came along with Windows XP SP2, but wherever it came from, it's a real pain in the you-know-what.

View 4 Replies View Related

Onblur Form Validation Not Working?

Feb 12, 2010

I am creating a form using php, with which I can successfully validate and strip html tags. What I am trying to do is use JS to automatically strip tags whenever the user leaves the text field so they see any changes before submitting.Here is my code:

Code:
<script type='text/javascript'>
/* <![CDATA[ */

[code].....

View 3 Replies View Related

User Can Close The Browser Or To Open The Window Browser Without Or With A Disable Close Window Button?

Apr 5, 2009

I need to know if the user close the browser or to open the window � browser without or with a disable close window button How can I???

View 6 Replies View Related

Trap The Window.close() Event When The User Clicks On The Close Button Of The Browser

Jul 20, 2005

I want to trap the window.close() event when the user clicks on the close button of the browser using javascript. Can anyone shed light on this problem ?

View 1 Replies View Related

Child Window Close Event - Opening Another Link In A Separate Window Using Window.open()

Jan 29, 2010

I have a HTML and I am opening another link in a separate window using window.open() . The child window is something like 'http://yahoo.com' which is out side html. I need to refresh the parent window when the child window is closed.

View 4 Replies View Related

Automatically Close Alert Box As Soon When It Appears?

Sep 17, 2011

I have an alert message just like
alert("Hiii");
I want to close it automatically as soon as it appears. It means I don't want to show this alert message to client.

View 7 Replies View Related

Close A Page With Alert/message

Mar 28, 2007

Before the user can close a page, I would like to have a message come up that asks if this is really what they want to do. the page needs to stay open.

I got this, edited, from msdn
function closeIt()
{
event.returnValue = "";
}
<body onbeforeunload="closeIt()" >

It works just fine, too well. I get the message when the user refreshes the page, something I do not want. Any thoughts?

View 8 Replies View Related

Automatically Close Alert Box As It Appears?

Sep 17, 2011

I have an alert message just like[code]...

I want to close it automatically as soon as it appears.

It means I don't want to show this alert message to client.

View 2 Replies View Related

"window.close()" Won't Close My Popup Window In Most Browsers

Apr 7, 2010

- I have a button on my Flash site that opens an HTML page in a popup window. In Flash, I open the new window using Actiosnscript 2.0:

- Within the popup window are links to other HTML pages. They all open in the same window. I've been using the following to create the links in Dreamweaver:

- On each page, I have a "Return to Main Menu" button that should close the popup window. To do this, I have been using:

- The problem is that it works differently in each browser, and I can't even get it to consistently close the window in most browsers:

Internet Explorer = popup message appears, asking "Are you sure you want to close this window?" or something similar; window closes after clicking "Yes."

Safari = Only closes if I'm on the original HTML page. If I click on any of the other links (note that these all open in the same window), those pages' "Return to Main Menu" buttons cease to work. However, if I keep clicking "Back" until I get to the original page, it closes.

Opera = Button actually works for each page.

Firefox & Chrome = Does not close the window at all.

I looked into it and saw that others have used a window.opener to solve similar issues. But, since my popup window is opened using Flash/AS2, I need to find a way around it.

I've tried preceding "window.close()" with "window.opener=null" (i.e. -onClick="window.opener=null; window.close()"), but I don't think I'm doing it right because it still doesn't work.

I've also seen others use codes that involve functions and variables, but it is beyond my current coding knowledge to implement this. Like I said, I'm sort of new at this.

View 5 Replies View Related

How Trigger Window.onblur?

May 23, 2002

I have a little popup window I'm making. I'd like the window to just destroy itself if the user clicks on the original, calling page.

This is what I tried in the header section of the popup page but the code is not being triggered:

<script type="text/javascript"> <!--
window.
-->
</script>

And by the way I already tried this in the body tag:

And the body tag thing actually DID close the window if the user clicked on the original calling page. BUT the window also closed if the user clicked on a combo box on the popup (because the body lost the focus), and that was not good..

View 1 Replies View Related

Cookies - Open An Alert Box When They Close Or Leave A Certain Domain

Dec 20, 2011

getting code to open an alert box when they close or leave a certain domain. The following script is from the above mentioned site.

Code:
<script type="text/javascript">
//Get cookie routine by Shelley Powers
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
[Code]...

View 1 Replies View Related

Textbox OnBlur Fires When Closing Window?

Dec 2, 2010

I have an input element (textbox) on a webpage, and capture the onblur event of the input (textbox) control to do validation. My problem is that when the page is closed or the user click on another window the onblur event of my textbox gets called too.

I need the onblur event handler to be called only when the textbox loses focus b/c another element on the SAME webpage gets focus, but not when the user clicks on another window or closes the browser window.

View 10 Replies View Related

Closing Popup Window With OnBlur Event Handler?

Jul 20, 2005

I want to close a popup-window with the onBlur eventHandler.
function closeIt() {
setTimeout('window.close()',2000); }
<body onBlur="closeIt()">
html
</body>

There is a form on my page, and when a input-field gets focus, body looses focus and the window closes. That's not what I want. I want to close the window, if focus goes to another
window or application, but not when someone tries to fill that form.

View 2 Replies View Related

Script To Close Old Window And Open New Window With New Link And Specific Size

Jan 29, 2006

I need a script that will open a new window (popup / new link) in a specific size, but will also close the old window (where the popup came from). I know the popup window is easy but finding a work-able close window script as the new window is opened is impossible!!

View 3 Replies View Related

Capture Child Window Close Event In Parent Window?

Feb 1, 2010

I have an HTML page where I am opening a child window using window.open. the child window is something like yahoo.com. I want to refresh the parent window when the child window is closed.

View 1 Replies View Related

Validation Without Alert()

Dec 13, 2006

I have the following code somewhat working:

function customerAdd(form){
if (form.email.value == ""){
var email = document.getElementById("email");
email.style.color = "red";
}
if(form.isActive[0].checked == false && form.isActive[1].checked == false){
var isActive = document.getElementById("isActive");
isActive.style.color = "red";
}
if(form.receiveEmails[0].checked == false && form.receiveEmails[1].checked == false){
var receiveEmails = document.getElementById("receiveEmails");
receiveEmails.style.color = "red";
}
if (form.salutation.value == "" || form.salutation.value == "- Please Select -"){
var salutation = document.getElementById("salutation");
salutation.style.color = "red";
}
return false;}

What I meant by somewhat working was that the code actually changes the color of the selected "id" when the fields are empty or have not been selected, but when all the required fields are selected the form doesn't do anything. I knwo it has to do with the return false;

How can I get this to work so that if the user doesn't fill out the required fields they would be highlighted and if everything is filled out the form will submit? I had the code working before with alert boxes, but I wanted to do something different with the way the validation worked rather than having the alert box pop up for each missed field.

View 3 Replies View Related

Close Child Window When Parent Window Closes?

May 3, 2009

I'm trying to create code to close the child window I'm creating if the parent window is closed. Here's my code so far:

function openWindow() {
var newWin = window.open(); // open the new window
newWin.document.write('<h1>Child Window</h1>

[Code]...

The above openWindow function is used in this event: <input type="button" name="btn" onclick="openWindow()"value="Open a new window" />

I can generate the new window fine. I just can't close it if the parent window is closed.

View 1 Replies View Related

Suppress F5 Key

Jul 23, 2005

I'm working on an app where the refreshing of the window by pressing the
F5 key needs to be suppressed. I thought it would be straightforward but
I can't get it to work. This is the code I'm currently trying:

okdh = function(e) {
if (e.which == 116) e.preventDefault();
}
document.addEventListener("keydown", okdh, false);


e.which returns a number
e.which returns 116 when the F5 key is pressed
e.cancelable is true when the F5 key is pressed

Is the default action of the F5 key something that can be suppressed?

View 3 Replies View Related

Form Validation Plus Exit Alert?

Sep 24, 2010

My issue is I would like to have this code validate my radio buttons on my form and also have an onscreen pop-up in the case that the user is exiting the page without filling out the form.I have had both of these peices of code working...but when I put both of them on the page the pop-up will override the validation script, and I don't wish to have the pop-up, pop-up when the user hits the submit button. Here are my pieces of code:Inside my head tag:

<script language="JavaScript">
function closeIt()
{

[code]....

View 3 Replies View Related

Simple Validation Not Working After Alert?

Nov 22, 2011

If the value is equal to 0 it will give an alert and return false. Then if you change the value of the drop down it won't let you submit.

<script type="text/javascript">
<!--
function validate_form ( )
{

[code]....

View 5 Replies View Related

Close All Child Window With Parent Window?

Nov 26, 2010

I have parent page with 10 child window and i want to close all child window when click on close session button on parent but first i need to check whether any child window open or not after that action should be done for close the child window.

View 4 Replies View Related

Close Window AND Go To New Page In Parent Window

Nov 2, 2004

I have a product that has many features. Clicking on a feature opens a popup window with explanation. There is a js Close Window link in each. All is fine so far.

Now in one popup window there is a reference to a different page of the main website. Is it possible to have a single text link both CLOSE the popup AND go to a new page in the parent window?

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved