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

one form, two buttons 1

Status
Not open for further replies.

smellykat

Programmer
Mar 4, 2002
33
US
This is more of an html question, but maybe you guys can help. I have a page with 2 buttons - one add, one delete. They are both in the same form. I can't get both buttons to work - either the add or the delete will work, depending on what my form action is. How do i fix this???
 
code? ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
There really is no code yet. I have my form:
<form name=&quot;form2&quot; method=&quot;post&quot; action=&quot;delete_partner.asp?ID=<%Response.Write(Request(&quot;ID&quot;))%>&quot;>

then 2 buttons:
<input type=&quot;image&quot; src=&quot;media/mp4_button_delete.gif&quot; width=&quot;71&quot; height=&quot;25&quot;>
<input type=&quot;image&quot; src=&quot;media/mp4_button_update.gif&quot; width=&quot;71&quot; height=&quot;25&quot;>
//proceed...
</form>

Now I know this way obviously both buttons will refer back to what is in the form. So i changed the Update button to an href:
<a href=&quot;<%Response.Write(&quot;update_partner.asp?ID=&quot;);Response.Write(Request(&quot;ID&quot;))%>&quot;><input type=&quot;image&quot; src=&quot;media/mp4_button_update.gif&quot; width=&quot;71&quot; height=&quot;25&quot;></a>

but this still doesnt work. It still goes to trade_partner.asp - from the form.

 
try
Code:
onclick=&quot;<%Response.Write(&quot;update_partner.asp?ID=&quot;);Response.Write(Request(&quot;ID&quot;))%>&quot;
---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
If you are going to use an href on your image, then change the tag to an img tag instead of an input tag:

<a href=&quot;<%Response.Write(&quot;update_partner.asp?ID=&quot;);Response.Write(Request(&quot;ID&quot;))%>&quot;><img src=&quot;media/mp4_button_update.gif&quot; width=&quot;71&quot; height=&quot;25&quot; border=&quot;0&quot;></a>
 
Juanita,
thanks. I had img there before...was just playing around. That doesnt change anything though.
 
Just an idea,
Why not use an OnClick method to call a JavaScript function
to change the form's behavior:
Like:

Code:
 OnClick=DoItForMe(this.form,1) for the delete button or
 OnClick=DoItForMe(this.form,2) for the Update one
then in the <HEAD> place:
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function DoItForMe(form,nbr)
var myform = form
if (nbr == 1) {
 acstr = &quot;Delete_Partner.asp&quot;
}
 else {
  acstr = &quot;Update_Partner.asp&quot;
}
// [i] Insert any other stuff here to set the passed
// parameters ( like ID ) , etc
//  like acstr = acstr + &quot;?ID=
[/i]
// now, once the action is defined set the form to do it.
form.action.value = acstr
// do it
form.submit()
// all done
</SCRIPT>
</HEAD>
This is very rough, but it may give you the idea..

hth,
[profile]
 
Ok, but before I use your idea, Turkbear, am I wrong in saying that there is a way, using onclick on my checkbox itself, to 'dynamically' delete that row as soon as its checked?
 
I got it to work. I changed one of the buttons to an href link, so no more problems.
Thanks for all your help.
 
I have a silly question, why do you do this:
your code
Code:
<a href=&quot;<%Response.Write(&quot;update_partner.asp?ID=&quot;);Response.Write(Request(&quot;ID&quot;))%>&quot;>


Instead of this:
my code
Code:
<a href=&quot;update_partner.asp?ID=<%=Request(&quot;ID&quot;)%>&quot;>

Not only is it more readable, but it may run faster too. I just thought it odd to use a Response.Write like you were. Either code will work, but anything you can do to keep your life easier will prevent mistakes and bugs down the road.

Also, I don't know if this came out in the other posts, but the <input type=&quot;image&quot; ...> acts just like a submit button. So your original question was &quot;I have a page with 2 buttons - one add, one delete. They are both in the same form. I can't get both buttons to work - either the add or the delete will work, depending on what my form action is. How do i fix this???&quot; The answer is that the image was just being a submit button for your form. That is why the action was being called.

If you wanted to you could go back to your original HTML form and put an onclick event that changes the form.action value. Something like this:
Code:
<input type=&quot;image&quot; src=&quot;media/mp4_button_delete.gif&quot; width=&quot;71&quot; height=&quot;25&quot;>
<input type=&quot;image&quot; src=&quot;media/mp4_button_update.gif&quot; width=&quot;71&quot; height=&quot;25&quot; onclick=&quot;document.form2.action='update_partner.asp?ID=<%=Request(&quot;ID&quot;)%>'>

There are multiple methods of feline taxidermy. :) Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top