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!

Using CFFORM 1

Status
Not open for further replies.

iao

Programmer
Feb 23, 2001
111
US
I have a form where the user has the option of deleting an item from a database. I have the following Javascript function set up:

function DeleteMe()
{
if (confirm ("Are you sure you want to delete the selected project?"))
{
document.forms[0].submit();
}
else
{
return false
}
}

In the form, I have the following set for the Delete button:

<INPUT TYPE=&quot;submit&quot; NAME=&quot;Button&quot; VALUE=&quot;Continue&quot;>
<INPUT TYPE=&quot;submit&quot; NAME=&quot;Button&quot; VALUE=&quot;Save&quot;>
<INPUT TYPE=&quot;button&quot; NAME=&quot;Button&quot; VALUE=&quot;Delete&quot; ONCLICK=&quot;DeleteMe()&quot;>

On my action page, I have the following code set up:

<CFIF IsDefined (&quot;form.button&quot;)>
do this
<CFELSE>
do that
</CFIF>

If the user selects &quot;Cancel&quot; on the confirm message, nothing happens (as is expected). However, when the user selects &quot;OK&quot;, the ELSE statement on the action page gets invoked. The problem is that the Delete button is not getting recognized (on the Action page, if I say something like IsDefined &quot;form.button&quot; - I get an error). I'm sure that this has something to do with the fact that I am using the buttons within CFFORM (rather than a simple FORM) and trying to submit the form using a Javascript function.

Any ideas on how to resolve this problem?
 
Try this:

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
function DeleteMe(){
if(confirm (&quot;Are you sure you want to delete the selected project?&quot;)){
return true;
}else{
return false;
}
}

//-->
</SCRIPT>



<CFFORM NAME=&quot;myForm&quot; ACTION=&quot;test.cfm&quot; METHOD=&quot;post&quot;>
<INPUT TYPE=&quot;submit&quot; NAME=&quot;Button&quot; VALUE=&quot;Continue&quot;>
<INPUT TYPE=&quot;submit&quot; NAME=&quot;Button&quot; VALUE=&quot;Save&quot;>
<INPUT TYPE=&quot;submit&quot; NAME=&quot;Button&quot; VALUE=&quot;Delete&quot; ONCLICK=&quot;return DeleteMe();&quot;>
</CFFORM>

<!--- Results page --->
<CFIF IsDefined(&quot;form.button&quot;)>
do this
<CFELSE>
do that
</CFIF> - tleish
 
Ah, I see. Do you know specially what happens when &quot;return DeleteMe&quot; is set to Onclick, versus &quot;DeleteMe&quot;.

I never know when to add the &quot;return&quot; to the attribute and when not to.
 
The function DeleteMe() only returns the variable &quot;false&quot; or &quot;true&quot;, not &quot;return false&quot; or &quot;return true&quot;

ONCLICK=&quot;return DeleteMe();

is really like putting:

ONCLICK=&quot;return false;&quot; -- stop, do nothing
or
ONCLICK=&quot;return true;&quot; -- go ahead and process the submit button


If you just put:
ONCLICK=&quot;DeleteMe();

is really like putting:

ONCLICK=&quot;false;&quot; -- doesn't affect submit
or
ONCLICK=&quot;true;&quot; -- doesn't affect submit - tleish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top