Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
multiple buttons on page?
Old 04-17-2006, 04:34 PM multiple buttons on page?
Novice Talker

Posts: 8
Trades: 0
I am new to web programming, and so far have found that trying to get stuff that seems straight forward with desktop applications to work via the web can be complicated. So if any of the assumptions I make below are incorrect let me know:

Having looked at ASP samples using VB script, buttons on a form have various properties defined in HTML (input type, name, and value).

It seems that input type defines what it is ('submit' seems to mean a button that refreshes the whole page without performing any extra code such as calling a function, etc.)

It seems that name defines the name of a button (or other object) in the samples I have seen, the name of the buttons seems to also be 'submit'? Which is a little confusing!

Finally, value appears to indicate the caption on the button itself, which if true is also kind of misleading (it should really be something like 'caption' or 'text')

Anyway in all the samples that I have, there is never more than one button on the screen, so what happens when you want two buttons on a page?

Lets say for the sake of an example, you want to have one button that when pressed displays "Hello World" in a textbox (and does this using VBScript) and another button, which when pressed displays "Good Bye World" in the same textbox?

If someone could provide a simple bit of code with this functionality (using VB Script), it would really help me to understand how buttons work on an ASP page.

Thanks in Advance,

Gareth

Last edited by gfunkera; 04-17-2006 at 04:38 PM..
gfunkera is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-17-2006, 05:49 PM Re: multiple buttons on page?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Value is used because that is the value sent to the server when the form is submitted along with the name to identify the key/value pair.

Quote:
Lets say for the sake of an example, you want to have one button that when pressed displays "Hello World" in a textbox (and does this using VBScript) and another button, which when pressed displays "Good Bye World" in the same textbox
Actually, you would do this with javascript rather than ASP as it would remove the round trip needed to submit the page and set the variables.

Two buttons on one page would be handled server side by checking the value of the submit button when submitted.
Code:
<%
dim btnPressed

if request.form("submit") <> "" then
btnPressed = lcase(request.form("submit"))

if btnPressed = "this_button" then 
' do this because this button was pressed 
else if btnPressed = "that_button" then 
' do this bcause that button was pressed
end if

end if
%>

<form name="this_form" method="post" action="">
<input type="submit" name="submit" value="This_Button">
<input type="submit" name="submit" value="That_Button">
</form>
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-18-2006, 01:46 PM Re: multiple buttons on page?
Novice Talker

Posts: 8
Trades: 0
Thanks for that chrishirst. That clears up a lot.

However, I have decided that I want images on the buttons, so I think I need to use an "imagefield" object rather than a button. Right?

I added an "imagefield" to my page (I am using Dreamweaver) but I did not get the same properties as the button. A "Value" property did not appear, can I just add one by typing it into the brackets?

I noticed that there is also an "Onclick" event for the image field, can I just add some VB Script code to this "Onclick" event with some <% %> brackets to indicate that it is VBScript and not HTML?

So really, unless there is a way of putting an image on the button object, my question is now how can i do the same thing, but with images instead of buttons?
gfunkera is offline
Reply With Quote
View Public Profile
 
Old 04-18-2006, 02:43 PM Re: multiple buttons on page?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
putting <% %> delimiters around vbscript means it will be executed on the server before the code is sent to the client.
Clientside vbscript is an Internet Explorer only operation so should only be used when you know that every user to the page will be using IE.

to use a image as a button;
Code:
<input type="image" src="path_to_image/imagename.ext" name="input_name" >
the image type input element also has the same properties as a <img> tag (alt text, height & width etc) and is by default a form submit button when clicked.
The difference being, is that the value passed to the server is the mouse x & y co-ordinates rather than the string contained in the value attribute.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-18-2006, 03:23 PM Re: multiple buttons on page?
Novice Talker

Posts: 8
Trades: 0
So how do I retrieve those x,y co-ordinates?

Even when I have the X and Y, it still seems a little crazy, I would have to say:

if x > (image bottom) and x < (image top) and y > (image left edge) and y < (image right edge) then

response.write "Hellow World"

end if

Also I want these images to look like buttons (i.e. 3D), not like flat images.
Its a shame there is no way to get the image on the buttons, that would make things a lot simpler.
gfunkera is offline
Reply With Quote
View Public Profile
 
Old 04-18-2006, 03:46 PM Re: multiple buttons on page?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
almost the same

Code:
request.form("input_name.x ")<> "" then 
'do something here
end if
unless you actually want the co-ordinates for processing simply checking that they are not empty is enough to determine if the page is opening or the button has been clicked.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-19-2006, 11:19 AM Re: multiple buttons on page?
Novice Talker

Posts: 8
Trades: 0
Ok I tried doing what you said but it is not working.

It is not entering in the "if" clause because

request.form("input_name.x ")<> ""

is not evaluating to true.

Take the code below and paste it into an ASP page and then run it, and you will see what I mean. Obviously you will have to change the image path to point to your own image.

Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="CP_ACP"%>
<%
if request.form("input_name.x ")<> "" then 
 response.Write("Hello World")
else
 response.Write("Button is not working")
end if
 
%>
<html>
<body>
<form name="form1" method="post" action="">
  <input name="input_name" type="image" src="navTools/zoom_in.gif" width="65" height="20" border="0">
</form>
</body>
</html>
gfunkera is offline
Reply With Quote
View Public Profile
 
Old 04-19-2006, 06:31 PM Re: multiple buttons on page?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
you have a space after the x


<added>
Mind you so did I
</added>
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to multiple buttons on page?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27085 seconds with 12 queries