View Full Version : submit button

01-17-2003, 07:40 PM
i have this problem of putting a button which is an image and then giving it the job of submit. i have this loop in my asp code:

if Request.Form("Submit") = "Submit" then

and in my body i have my image button which is image.gif

<input type="Image" value="Submit" src="images/SUBMIT.gif" width="90" height="22">

i tried this but it doesn't work. does the loop read the input type or the value?

01-17-2003, 08:22 PM
I think it must be done with javascript.

<form name="myform" action="somewhere.asp" method="get">
<a onclick="document.myform.submit()" href="#"><img src="image.gif"></a>

01-17-2003, 09:05 PM
but then with this code even the user doesn't put any username and password
simply clicking on the image button they'll be redirected to the other page.
is it right or am i thinking wrong?

know i am clear with my problem...i did make the if loop to read the input type and input type must be "submit " for this loop to run.i need to find a way of keeping the input type"submit" but still be able to use my image button which has the original input type "image".

Any idea?

01-17-2003, 09:11 PM
With that script, the link is acting just like a submit button so any other fields that were in the form would be submitted like normal.:thumbsup:

01-17-2003, 09:15 PM
no i tried it it's not the right way. i should find a way of giving this image button input type "Submit" where its original input type is "image".

Like i told before with the js u suggested it's not redirecting you to the page besides even without putting username and password it redirects u but not to the actual page i want to a blank page.

i need to find a way of keeping the input type submit however it is image.

01-17-2003, 09:22 PM
If you had:
<form name="myform" action="somewhere.asp" method="get">
<input type="text" name="username">
<input type="text" name="password">
<a onclick="document.myform.submit()" href="#"><img src="image.gif"></a>

& your "somewhere.asp" checked if the username & password were entered, then could you not play around with it & do whatever you want with it from there?
Maybe I just dont know what u want.

01-17-2003, 09:23 PM
<%@ Language = "VBScript"%>

'Declare all local variables
dim conn
dim rs
dim strconn
dim strSQL
Dim strUserName
Dim strPassword

if Request.Form("Submit") = "Submit" then

strUserName = Request.Form("username")
strPassword = Request.Form("password")

Set conn = Server.CreateObject("ADODB.Connection")
Set rs= Server.CreateObject("ADODB.RecordSet")
'set connection string to local variable-I use a DSN-less connection
'Need to modify just this line.Point to right path to database file.
conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\anticus\db\Book Details.mdb"))
'build the sql statement based on the input from the form
strSQL = "SELECT * FROM Users WHERE UserName='" & strUserName & "' AND Password='" & strPassword & "'"
rs.open strSQL, conn

'Use the execute method of the connection object the insert the record

if rs.eof or rs.bof then
Response.Write("<center><font color='red'>Invalid Username or Password</font></center>")
Session("UserName") = strUserName
Response.Redirect "Control.asp?qUserName=" & strUserName
end if

set conn = nothing

end if


<form action="introduction.asp" method="post" name="IntroductionForm">

<div id="Layer4" style="position:absolute; left:571px; top:396px; width:86px; height:19px; z-index:4">
<input type="text" name="username">
<div id="Layer6" style="position:absolute; left:571px; top:431px; width:144px; height:21px; z-index:6">
<input type="password" name="password">
<div id="Layer8" style="position:absolute; left:275px; top:561px; width:90px; height:16px; z-index:8"> <a onclick="document.IntroductionForm.submit()" href="control.asp"><img src="images/SUBMIT.gif" width="90" height="22"></div>

this is my code.so do u think that way still works?

01-17-2003, 09:28 PM
if introduction.asp is the page your already on, that should work...

01-17-2003, 09:29 PM
my redirection is already in ASP code so i think that's not the way u suggessted is working.

i am not really professional in ASP these are my first tries. so if i delete the redirection bit in ASP part do u think it'll work?:(

01-17-2003, 09:33 PM
Well, if you were wanting 2 log in the user using that same page, the form would have to be going back to the page that your on. (eg. ur page should be called introduction.asp)
Then I would take out the If Request.Form("submit") blah blah & put in something like
If Len(username) > 0 & Len(password) > 0 Then
Then the redirect should take you to where ever you want them to end up.

01-17-2003, 09:38 PM
well actually th user registers at registration page this introduction page is for existing users to log on. if they don't have a username and password then first they get it by clicking the link on introduction page.

so in this case the page is just for logging in not registering.
do u think that way u suggested is still valid?

01-17-2003, 09:42 PM
edit: after reading through the thread, I am way off. You can probably ignore this post.

<input type="image"> triggers the onsubmit() event so you can use it directly as a submit button. Is this similar to what you need?

<script language="javascript">
function validate(theform){
var error_msg="";
if (theform.uname.value=="")
error_msg="enter a username\n";
if (theform.pwd.value=="")
error_msg+=error_msg="enter a password\n";

if (error_msg=="")
return true
alert('You have errors\n'+error_msg)
return false;
<form name="myform" action="somewhere.asp" method="get" onsubmit="return validate(this);">
<input type="text" name="uname"><br>
<input type="password" name="pwd"><br>
<input type="image" name="point" src="map.gif">

01-17-2003, 09:46 PM
I would think so, I saw that that was a login page, so the way i described should work. So long as the form is submitting itself to the page its on, then it should work.:thumbsup:

01-17-2003, 10:21 PM
well yeah but it has some differences as well

because in this js it just checks if the user has out a username or password else it gives errors.

there should be another option like if the user name and password is equal to the one that they entered the first time they registered then the user should be redirected to another page.

so can i add another if

where it cheks that the password and the username is one of those staying in database from the first time users has registered?
this is sort of mixing the asp with javascript.

if yes how can i do it?

01-17-2003, 10:33 PM
You shouldn't need Javascript to check if the username & password exists as ASP does this for you. That javascript would really be unneccisery

01-17-2003, 10:49 PM
ok i tried the way u suggested and as far as i am checking the length of password and username i need to read the data that the user has put as a username and password which was

strUserName = Request.Form("username")
strPassword = Request.Form("password")

i used to ask for those after if loop that i used to use b4 but as far as now i am using the lenght one where shall i put those bits in my ASP code.

the other thing i am still confused is that in my ASP it does the job of redirecting so y m i still using <ahref=" ">

i know i am being thick but :((

01-17-2003, 11:14 PM
Well u would get the values 1st with the:
strUserName = Request.Form("username")
strPassword = Request.Form("password")

& then you would put:
If Len(strUserName) > 0 & Len(strPassword) > 0 Then

after that.
The reason you are using the <a href= is because that is includes the onclick which submits the form.
You could just use (I believe):

<a href="javascript:document.myform.submit()"><img scr"..."></a>

& the href is what u use to initiate the whole javascript submitting... thingy...

I hope this helps:thumbsup: