Firing order... why???

J

John Kiernan

I have a routine in the MouseUp of a 'Save' button on a form. The button is
a Submit button.

If I find anything wrong in my routine, I alert the user and return a False.
If I find nothing, I return a true and things save just fine.

Except...

Under certain circumstances, I use a Confirm() dialog box. When I do, even
when I return a true, the Form does not submit.

Anyone know why? Thanks in advance!

-- John Kiernan, KierPro Associates
Custom VFP/Accounting Programming
and Web interfaces
VFP and/or SQL back ends
 
R

Randy Webb

John said:
I have a routine in the MouseUp of a 'Save' button on a form. The button is
a Submit button.

If I find anything wrong in my routine, I alert the user and return a False.
If I find nothing, I return a true and things save just fine.

Except...

Under certain circumstances, I use a Confirm() dialog box. When I do, even
when I return a true, the Form does not submit.

Sometimes, my light comes on and sometimes it doesn't, can you tell me why?

The point is, you don't provide enough information to answer you.
Provide a URL to a simple test case, or post the minimum code to display
the problem (preferably a URL).
 
J

John Kiernan

Sure... here's the code. The last part with the Confirm() is at the bottom.
If it's really amatuerish (I'm sure it is), please bear with me, I'm on the
learning curve...
Thanks for the help!
-- John

function cliservsave() {
lvIsnew = document.getElementById('isnew');
lvIsnewV = lvIsnew.value
lvRepf = document.getElementById('repfreq');
lvRepfV = lvRepf.value;
lvNotes = document.getElementById('NOTES');
lvNVal = lvNotes.value;
lvNotComp = document.getElementById('NOTCOMP');
lvNCVal = lvNotComp.checked;

if (lvNVal == "" && lvNCVal == true) {
alert("If Not Completed, Notes MUST be entered.");
return false;
}

lvDescrip = document.getElementById('DESCRIP');
lvDVal = lvDescrip.value;
if (lvDVal == "") {
alert("Description Cannot be Blank.");
return false;
}

if (lvIsnewV == "true" && lvRepfV !== "None") {
var lvAnswer='';

lvAnswer = confirm("Are you sure you want to generate multiple records?")
if (lvAnswer == false) {
return false;
} else {
return true;
}
}

return true;
}
 
R

Randy Webb

John said:
Sure... here's the code. The last part with the Confirm() is at the bottom.
If it's really amatuerish (I'm sure it is), please bear with me, I'm on the
learning curve...
Thanks for the help!

lvAnswer = confirm("Are you sure you want to generate multiple records?")
if (lvAnswer == false) {
return false;
} else {
return true;
}
}

Without digging through it, the first thing I noticed was that the above
could be rewritten as:

return (confirm("Are you sure....."))

Since you return the value of lvAnswer, you can simply return lvAnswer,
which leads to just returning the confirm.
 
J

John Kiernan

Dear Randy -
Thanks... that tip was a good one that saved of lines of code (ironically,
that's how I'd do it in Visual FoxPro, my main language).

Now I have this:

if (lvIsnewV == "true" && lvRepfV !== "None") {

return confirm("Are you sure you want to generate multiple records?")
}

But...

It still inhibits the Submit, no matter which option on the Confirm is
chosen.

Help!

-- John Kiernan, KierPro Associates
Custom VFP/Accounting Programming
and Web interfaces
VFP and/or SQL back ends
 
H

Harag

Sure... here's the code. The last part with the Confirm() is at the bottom.
If it's really amatuerish (I'm sure it is), please bear with me, I'm on the
learning curve...
Thanks for the help!

Hope the below helps.

1st. Rather than putting your validate calling code on the "onmouseup"
event put it on the "onsubmit" event on the form.

<form onsubmit="cliservsave();" method="get">
<!-- Other input elements here -->
-- John

function cliservsave() {
lvIsnew = document.getElementById('isnew');
lvIsnewV = lvIsnew.value
lvRepf = document.getElementById('repfreq');
lvRepfV = lvRepf.value;
lvNotes = document.getElementById('NOTES');
lvNVal = lvNotes.value;
lvNotComp = document.getElementById('NOTCOMP');
lvNCVal = lvNotComp.checked;

if (lvNVal == "" && lvNCVal == true) {

This can be written as:

if (!lvNVal && lvNCVal)
* note the "!" near the beginning.
alert("If Not Completed, Notes MUST be entered.");
return false;
}

lvDescrip = document.getElementById('DESCRIP');
lvDVal = lvDescrip.value;
if (lvDVal == "") {

again :

if (!lvDVal) {
alert("Description Cannot be Blank.");
return false;
}

if (lvIsnewV == "true" && lvRepfV !== "None") {
var lvAnswer='';

lvAnswer = confirm("Are you sure you want to generate multiple records?")
if (lvAnswer == false) {
return false;
} else {
return true;
}
}

see. R.Webs post about the above confirm.
return true;
}


HTH

Al.
 
A

Alberto

I haven't time to peruse all the code, yet just a hint: do you have in your
to be submitted form an onSubmit event handler? That should read :
<form etc etc onSubmit="return functionNameHere()">

Do you have in your form tag an action property? Forms to be submitted need
to specify WHERE they have to be submitted, or they just never get submitted
no matter what the return value.

Also, you mention this line
if (lvIsnewV == "true" && lvRepfV !== "None") {
return confirm("Are you sure you want to generate multiple records?")

But in your PREVIOUS code it doesn't include the RETURN statement you
include above.
In the code it reads:

if (lvIsnewV == "true" && lvRepfV !== "None") {
lvAnswer = confirm("Are you sure you want to generate multiple records?")

which version are you actually using?

But as said and maybe more significantly, have you included an action
property in your FORM tag?

A mock up example can be:

<form action="dunno.php" onSubmit="return foo()">
<script><!--
function foo(){
return confirm("Are you sure you want to generate multiple records?")
}
//--></script>
<input type="submit" value="TEST">
</form>

That works in the expected way.

I hope this helps
ciao
Alberto
http://www.unitedscripters.com/
 
D

Denzil

Hi,

Could you also post the "<form..." and the "<input type='submit'..." code lines?

Top of the mind, hope that you do have the following code,
<input type='submit' value='Save' THE_EVENT='return cliservsave();'>

HTH.
Cheerz,
Denzil
 

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,781
Messages
2,569,619
Members
45,316
Latest member
naturesElixirCBDGummies

Latest Threads

Top