need help determining the return value of a generated js onChange event

M

MDBloemker

can anyone help me fathom out how to use this bit of code:

Public Class Utilities
Public Shared Sub CreateConfirmBox(ByRef txt As WebControls.TextBox,
_
ByVal strMessage As String)
txt.Attributes.Add("onchange", "return confirm('" & strMessage &
"');")
End Sub
End Class

invoked thusly:
Utilities.CreateConfirmBox(Me.txtDelete,  "Are you sure you want to
delete (this uses the Utilities Class)?")

Works great. However....

The ever-so-helpful page I stole this from explains:
The client-side JavaScript confirm(string) function displays a confirm
message box, displaying the string message passed into the function.
Recall that confirm message boxes provide both "OK" and "Cancel"
buttons. If the "OK" button is clicked, confirm() returns true; if
"Cancel" is clicked, it returns false. The return keyword is used to
return the result of the confirm message box. If a value of false is
returned, then the form is not submitted.

What it's NOT telling me is how to get the value returned by the
javascript confirm(). I've already determined that I can't assign some
sort of flag to either the call or the class. This would be ever so
helpful if I can just figure out how to get the true/false value so
that I can handle program flow.

If the answer turns out to be blindingly obvious, I'll be very annoyed
at myself, but at the same time eternally grateful to whomsoever turns
the light on. Thanks!

MDBloemker
(e-mail address removed)
 
B

Ben Dewey

This code would work on a submit button onclick event. because by default
if you return true the submit continues and if you return false the submit
terminates. Now, if you use it on a textbox, you will not get the same
results.

What are you confirming a delete of on the change event of a textbox?

There are a couple work arounds if you were trying to do this on the
onchange event, but I would need some more info on what exactly you are
trying to do. ie. Are you planning on submitting a form when the change
something, or are you planning on not letting them change the value in a
text field.
 
M

mdb

I finally figured it out shortly after I posted. It does nothing to
help with program flow, which what I was looking for in the first
place. It merely provides a true/false method to determine whether or
not to set off the _textchanged event.

What I was looking for was a large, in-your-face ok/cancel popup that
would control program flow. The example I posted was actually
misleading, sorry; the original example was for a delete action from a
button, I'm really trying to intercept the change event on a textbox.
This particular textbox is only enabled when the user elects to add a
new record. It's the key field, and must therefore be unique. After
input, I want the process to quickly query the table to see if that
key already exists. The in-your-face popup with ok/cancel is primarly
a user expectation; they're used to grey boxes popping up and blocking
their way when they do something wrong. Ideally, the message would be
"Click OK to overwrite the existing record, Cancel to return to the
main screen".

With this control, I found I can give them the popup, which would be
nice except it would always fire onchange, even if the input were
acceptable. That's why it was originally a button-click-event, duh.
And even then I would only have two choices as regards program flow:
fire the _textChanged event or don't.

Are there any other alternatives I can pursue, or should I just expect
to re-train my users to look for error messagesthat require decisons
on a certain part of the form?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top