PDA

View Full Version : Calling value from Form Button.


Icedan
11-30-2006, 04:28 AM
See this page: http://www.orient-explorer.com/Cityscape/

You will see each hotel has a button, each button has a value (hotel name it represents).

When you click on the button, you will go to the booking page, scrolling down, you can see the 1st Hotel Name, it has the name (or it should have the name) of the hotel you selected to book.

Here is the code:

The code on the index page, the button:
<input name="RitzCarlton" type="submit" id="HotelSelect" value="Click here to book this hotel">

The code on the booking page (in the head):
<%
Dim HotelName
Dim HotelSelect

if HotelSelect = Ritz then
HotelName = "Ritz Carlton"
if HotelSelect = Conrad then
HotelName = "Conrad Centennial"
else if HotelSelect = Marina then
HotelName = "Marina Mandarin"
else if HotelSelect = Meritus then
HotelName = "Meritus Mandarin"
else if HotelSelect = Carlton then
HotelName = "Carlton"
else if HotelSelect = Coleman then
HotelName = "Parkroyal on Coleman Street"
else if HotelSelect = Beach then
HotelName = "Parkroyal on Beach Road"
else if HotelSelect = Bayview then
HotelName = "Bayview"
else if HotelSelect = Dickson then
HotelName = "Dickson Court"

end if
end if
end if
end if
end if
end if
end if
end if
%>

And the code for the 1st Hotel:
<input name="HotelName" type="hidden" id="HotelName" value="<%= HotelName %>">
<%= HotelName %>

If you test the website, you can see that it seems to work, but for some reason, no matter what hotel button you push, you always get Ritz Carlton, what's going on?

Icedan
11-30-2006, 04:34 AM
argh, sorry, I notice the missing "else" in the 3rd line of the second code snippet, I try to edit the post, but it won't save, just hangs.

Anyway, that mistake is not in my code, so ignore it. :D

Spudhead
11-30-2006, 05:42 PM
Well... couple of things.

It's probably not helping that your submit button has a different name to its ID. And if you've got a lot of buttons on the page with an ID of "HotelSelect", that's not going to help much either. ID's should be unique.

The embedded IF statements would be better as a SELECT:

select case HotelSelect
case Ritz
HotelName = "Ritz Carlton"
case Conrad
HotelName = "Conrad Centennial"
end select

But the main thing that immediately jumps out is - is Ritz a variable name? Shouldn't it be if HotelSelect = "Ritz" then ? And where are you actually getting the posted form values?

Icedan
12-01-2006, 03:48 AM
Ok, I have gone through it, but I still cannot find a solution to my problem.

degsy
12-01-2006, 02:56 PM
You have several errors.

<input name="RitzCarlton" type="submit" id="HotelSelect" value="Click here to book this hotel">
When this is clicked it produce a Request element called "RitzCarlton" with a value of "Click here to book this hotel"

In your script you are checking
if HotelSelect = Ritz then
No where in your code have you assigned a value to HotelSelect or Ritz

What I assume you want would be

If Request("RitzCarlton") <> "" Then
HotelName = "Ritz Carlton"
ElseIf Request("Conrad") <> "" Then
HotelName = "Conrad"
ElseIf...
...
End If



You would be best off storing the Hotel IDs and names in a database instead of doing a hardcoded check.

Icedan
12-04-2006, 03:27 AM
Oh! Now I see what I did wrong, I never requested the values! haha


Thanks Degsy, worked. :)

btw, yes a database would be nice, but too much extra work for me to bother with since this is just a simple temporary submit form.