![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Dear ASP.NET Programmers, I have a question about a script I'm trying to code and invoke when a button (btnSave) is pressed on the page. This script should only run when a textbox (txtAD) on the page is left blank. I tried to use a code snippet with the "return confirm" function but without success. The code should check whether the textbox is empty or not, and if empty, it should ask the user to continue and then run the next code. How can I accomplish this? Thanks in advance, Buran |
#3
| |||
| |||
|
|
Buran, you're going to want to capture the client onclick event of your save button, and run the script from there. First, in your codebehind append the client event handler: btnSave.Attributes.Add("OnClick","return CheckForEmptyTextbox();"); Now the javascript function CheckForEmptyTextbox will be called when the button is clicked. This function needs to return a boolean value, telling the page whether or not to submit the form. script language="JavaScript" function CheckForEmptyTextbox() { var continue; var txtAD; // first get a reference to the textbox object txtAd = document.getElementById('txtAD'); // check if the textbox is blank if (txtAD.value == '') { // since the textbox is blank, ask the user if they want to continue continue = confirm('txtAD is blank, do you want to continue?'); return continue; } // end if // since the value is filled in, just return true return true; } // end function /script buran wrote: Dear ASP.NET Programmers, I have a question about a script I'm trying to code and invoke when a button (btnSave) is pressed on the page. This script should only run when a textbox (txtAD) on the page is left blank. I tried to use a code snippet with the "return confirm" function but without success. The code should check whether the textbox is empty or not, and if empty, it should ask the user to continue and then run the next code. How can I accomplish this? Thanks in advance, Buran |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |