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

Syntax for "which submit button submitted?" 2

Status
Not open for further replies.

GaryCam

Programmer
Dec 16, 2003
69
US
I've seen this addressed in other forums but the answers are always beyond me. Please explain as simply as possible. We're talking Baby Talk here.

Here's what I have on the form page which is cart.asp:

Code:
<td>
  <a name="anchor1"></a>
  <input type="hidden" name="whichSubmitButton" value="1" >
  <input type="text" id="q1oz" name="q1oz" value="<% = q1oz %>" >
  <input type="image" name="imageField" onClick="submit();" src="add2cart.gif">
</td>

<td>
  <a name="anchor2"></a>
  <input type="hidden" name="whichSubmitButton" value="2" >
  <input type="text" id="q8oz" name="q8oz" value="<% = q8oz %>" >
  <input type="image" name="imageField" onClick="submit();" src="add2cart.gif">
</td>

When any of the submit buttons are clicked, the form is posted to a processing page, process.asp, which ends with this:

Code:
If Request.Form("whichSubmitButton") = "1" Then
  Response.Redirect "cart.asp#anchor1"		
If Request.Form("whichSubmitButton") = "2" Then
  Response.Redirect "cart.asp#anchor2"	
Else
  Response.Redirect "default.htm"
End If

As it stands, after receiving and processing the data, process.asp stalls and the screen goes white. What I want is to return to the anchor associated with the submit button that was clicked.

What I need to know is this:
1) how do I assign a unique value to each submit button in cart.asp?
2) how do I get the value associated with a given submit button passed when that submit is clicked?
3) and how do I reference that value in my conditional redirect in process.asp?

Any help appreciated. I've run out of hair to pull out.

~ Gary
 

Try this:

Code:
<td>
  <a name="anchor1"></a>
  <input type="hidden" id="whichSubmitButton" value="0" >
  <input type="text" id="q1oz" name="q1oz" value="<% = q1oz %>" >
  <input type="image" name="imageField" onClick="document.getElementById('whichSubmitButton').value=1;submit();" src="add2cart.gif">
</td>

<td>
  <a name="anchor2"></a>
  <input type="text" id="q8oz" name="q8oz" value="<% = q8oz %>" >
  <input type="image" name="imageField" onClick="document.getElementById('whichSubmitButton').value=2;submit();" src="add2cart.gif">
</td>
 
Thanks for taking a stab, nicsin, but that doesn't work either. The processing page is not receiving the value for 'whichSubmitButton'. The conditional that checks its value falls through to the default redirect every time.

Would it have anything to do with the fact that this form is POSTed?

~Gary
 
Your server-side code should be

Code:
If Request.Form("whichSubmitButton") = "1" Then
  Response.Redirect "cart.asp#anchor1"        
[COLOR=red]Else[/color] If Request.Form("whichSubmitButton") = "2" Then
  Response.Redirect "cart.asp#anchor2"    
Else
  Response.Redirect "default.htm"
End If
 
sorry no space

Code:
If Request.Form("whichSubmitButton") = "1" Then
  Response.Redirect "cart.asp#anchor1"        
[COLOR=red]ElseIf[/color] Request.Form("whichSubmitButton") = "2" Then
  Response.Redirect "cart.asp#anchor2"    
Else
  Response.Redirect "default.htm"
End If
 


You have 2 inputs with the same name.
What do you get from this code?

Code:
If Request.Form("whichSubmitButton")(1) = "1" Then
  Response.Redirect "cart.asp#anchor1"        
If Request.Form("whichSubmitButton")(2) = "2" Then
  Response.Redirect "cart.asp#anchor2"    
Else
Response.Write("<p>")
Response.Write("whichSubmitButton=" & Request.Form("whichSubmitButton"))
Response.Write("</p><p>")
Response.Write("The name property's count is: ")
Response.Write(Request.Form("whichSubmitButton").Count)
Response.Write("</p>")
End If

I don't know nothing. I'm just guessing.

 
Thanks again, nicsin, but I had already fixed that & it still doesn't work. Thinking I had some remnant of code affecting that variable I changed the variable name to aargh and it still doesn't work. It just falls through to the default.

~ Gary
 
Thanks, BigRed1212,
First I got 'Expected End'
After adding an END, I got 'Expected If'
After adding that, now the screen goes blank white.
 

What is the value of Request.Form("whichSubmitButton") at the server?
 
I don't know how to check the value at the server.

Firefox is giving me the following error:
document.getElementById('whichSubmitButton')HAS NO PROPERTIES


 
Hi nicsin,

OK, with this submit command:
Code:
onClick="document.getElementById('whichSubmitButton').value=5;submit();"

And this at the receiving page:
Code:
  If Request.Form("whichSubmitButton") = "5" Then
    Response.Redirect "basket2.asp#oz1"	
  ElseIf Request.Form("whichSubmitButton") = "6" Then
    Response.Redirect "basket2.asp#ml125"
  Else
    Response.Write("whichSubmitButton=" &  
    Request.Form("whichSubmitButton"))
    Response.Write("The name property's count is: ")
    Response.Write(Request.Form("whichSubmitButton").Count) 
  EndIf

I get this from the server:
whichSubmitButton=0
The name property's count is: 1

So apparently the value is not being sent. Any ideas?

Thanks again & again,
Gary
 
My first post should work if you have fixed the elseif mistake. Are you sure you substituted your code with mine? I only left one instance of the hidden control (you had two) and changed its name attribute with an id. It definately works at my end...
 
Hi nicsin,
I copied & pasted your first post and it still doesn't work. There must be some conflict at play here. The server still tells me it has not received the value for whichSubmitButton. There are many other things going on on both my source and my processing pages so I suspect there's something in all that other code that's preventing it.

For now I've given up. I'll just have the processing page send the user to the shopping cart instead of back to the submit button. Maybe someday I'll have time to revisit this.

Thanks a million for your help. I've learned a lot!

All the best,
Gary
 
[0] First and foremost, the input type "image" is itself a submit thing, so it is no good to add submit() to the onclick button.

[1] You should take out all the hidden "WhichSunmitButton" input controls (including the not posted part) out except one, if you have missed that point in the nicsin's post.

[2] Since it is itself a submit button, the onclick shouldn't contain the submit() line. This is a rewrite of nicsin's lines.
[tt]
<td>
<a name="anchor1"></a>
<input type="hidden" id="whichSubmitButton">
<input type="text" id="q1oz" name="q1oz" value="<% = q1oz %>" >
<input type="image" name="imageField" onClick="document.getElementById('whichSubmitButton').value=1;return true;" src="add2cart.gif">
</td>

<td>
<a name="anchor2"></a>
<input type="text" id="q8oz" name="q8oz" value="<% = q8oz %>" >
<input type="image" name="imageField" onClick="document.getElementById('whichSubmitButton').value=2;return true;" src="add2cart.gif">
</td>
[/tt]
 
Thanks, tsuji, but it still won't send the value.

~ Gary
 
[3] The value is sent. Only you've to capture it correctly because "name" is for server-side's consumption.
[tt]
<input type="hidden" [red]name="whichSubmitButton"[/red] id="whichSubmitButton">
[/tt]
Then you read it using request.form("whichSubmitButton") if the method is "post".
 
Gary,

can you post your code for the whole form?

<form...>
.
.
.
</form>
 
Yes, tsuji, that's exactly what I have. But as I said in a previous post, there is some conflict taking place because after clicking the button:

Request.Form("whichSubmitButton") returns nothing and
Request.Form("whichSubmitButton").Count returns a zero

Doesn't that mean that the value is not reaching the server?

~ Gary
 
If you conclude anything relying on this line:
> Response.Write("whichSubmitButton=" &
Request.Form("whichSubmitButton"))

You've to tell use if there is a line-break after "&" as it is not clear from the post.

There isn't anything mysterious about this. I am not prepare to accept supernatural in this regard.
 
Nicsin & Tsuji, Thanks so much for your help. I now have it working thanks to both you. I mocked up a sender page and a receiver page with no extraneous code and it worked fine. So I knew the problem lied elsewhere.

I was not familiar with this application (could you tell?) so I spent the last 3 hours or so tracing every line of code. I found a function calling a function calling a function... and deep inside was a variable named, you guessed it, whichSubmitButton!

I renamed the variable and it works like a charm. Now I know why programmers come up with variable names like Fx38gVVy. A valuable lesson learned.

Thank you again,
Gary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top