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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I do determine which button is selected?

Status
Not open for further replies.

jruiseco

Programmer
Oct 10, 2001
52
0
0
US
I have a form that enables something to be deleted or something to be updated. I am inserting values dynamically based upon which submit button is selected.

I need to know how to say:

"If this button was clicked..."

This is what I have but it doesn't work...

if (document.forms[0].SubmitForm.submit() == true)

Thanks...


 
well ... i would recomend that u change the submit button into an ordinary button, meaning:

<input type=&quot;button&quot; value=&quot;submit&quot; onclick=&quot;processClick()&quot; name=&quot;IAmAButton&quot;>

later u can use the onclick even to call the function processClick ().

function processClick () {
//enter your coding here;
}

hope this is wat u are asking about
 
You have to do it like this:

<input type=&quot;button&quot; value=&quot;action 1&quot; onclick=&quot;doThis()&quot;>

<input type=&quot;button&quot; value=&quot;action 2&quot; onclick=&quot;doThat()&quot;>

because a form can contain only one Submit button.
 
if you're using server-side script like asp, you would give your submit buttons different names:

<input type=&quot;submit&quot; name=&quot;action1&quot; />
<input type=&quot;submit&quot; name=&quot;action2&quot; />
<input type=&quot;submit&quot; name=&quot;action3&quot; />

then in the server side code, something like (in asp):
[tt]
if request.form(&quot;action1&quot;) = &quot;submit&quot; then
rem do action1 stuff here...
elseif request.form(&quot;action2&quot;) = &quot;submit&quot; then
rem do action2 stuff here...
elseif request.form(&quot;action3&quot;) = &quot;submit&quot; then
rem do action3 stuff here...
end if

[/tt]
=========================================================
if (!succeed) try();
-jeff
 
Okay, I took starway's advice.

Now it is working except I want to confirm with the user before deleting. When I get the confirm and hit okay, nothing happens. When I remove the return confirm statement altogether, the form submits and deletes just fine.

Here is what I am using...

document.forms[0].Action.value = 'Delete';
document.forms[0].TempAction.value = 'Delete';
return confirm(&quot;Are you sure you want to delete this product?&quot;);
document.forms[0].submit();
 
First of all, what does &quot;Action.value&quot; mean?
If it's some value that you assign to form field with such a name, change it because [tt]action[/tt] is JS-reserved word that corresponds to form's action() method.
If it's a new form action you're assigning, it should be done like this:

document.forms[0].action = &quot;targetpage.cgi&quot;;
(note that &quot;action&quot; is lowercased - javascript is case-sensitive)

about confirmation, this is how to do it:

if (confirm(&quot;Are you sure you want to delete this product?&quot;))
document.forms[0].submit();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top