Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onChange event with Javascript Confirm

Status
Not open for further replies.

dcusick

Technical User
Aug 9, 2000
271
US
Okay, I have a few things I need processed when a user changes a value in a textbox. The only thing is, I need to ask the user if they want to process them when they change the value or not. I was able to add a confirm popup to an onClick event of a button. If the user clicks yes, it continues, if no, it stops. This is exactly what I'm looking for. However, it doesn't seem to be working with the onChange event of the textbox. My Server-side function is being called upon submit, but the Confirm box is not being called. I am probably doing something wrong... Here is my code to add the Confirm Box...

Code:
txtBox.Attributes.Add("onchange","javascript:if(confirm('Would you like to Process?')== false) { window.event.returnValue = false; return false; }");

Is this right? Is this even possible to add to the client side event? If not, how would I add a Confirm Box to an OnChange event? Thanks in advance!

Doug
 
How about using the onBlur event instead of onChange?

HTH

tigerjade

"Always code as if the person who ends up maintaining your code will be a violent psychopath who knows where you live." -- Martin Golding


 
One thing that I've done in the past was to have a hidden text box...with the value of 0...

then with the onchange event of a textbox, i update the hiddedn textbox to read 1...


then the confirm msgbox on the button will prompt the user with 'Do you want to process changes?' only if the textbox.value = 1...

not sure if this is something that would work for you...

are you trying to use the Onchange in Javascript And the Onchange in the server-side code?

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Thanks for that. The Javascript Confirm actually does come up if I change it to onBlur. However, I can't really tell if the value was just tabbed-in/tabbed-out of, or it was changed. So, it has now been decided to run these processes on submission of the form. So, now I have another issue...

How can I add the javascript Confirm pop-up to the Server-Side txtBox_Changed()? So when the form submits, and the Changed event fires on the server, I would like to be able to ask the user if they would like to run the processes then...

Hope this isn't getting confusing... Unclear requirements always cause this!!! Thanks again..

Doug
 
personally, i would not do a postback on the server side onchange...it will post every time you type...not sure how much a user can type or how many text boxes, but that could be a lot of posting back on one page...

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Okay, I didn't explain it well.. I'm sorry...

I will not have AutoPostBack set to true... So the Text Box's Changed event will not fire until the user submits the form, which is done with a Submit button.
 
that's not how it works...in order for the text box's onchange event to fire, you have to set it to autopost back...

so whatever code you want to execute will have to be on your button click..

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Okay, I understand that, and I actually don't really care if it fires right away, actually, I don't want it to fire on tab out. I want it to fire upon Submit. Even with AutoPostBack=false, the event will fire if the box changes, when the form is submitted.

Therein lies my problem. I need to call a JS confirm box from my server-side Changed function. If the user clicks yes, then continue the Changed function, if not, then I need the changed function to stop, and the form to continue posting...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top