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

Passing form values with images

Status
Not open for further replies.

lahddah

Programmer
Jan 2, 2003
109
0
0
US
Hi. I know there are quite a few threads here that deal with this subject, and I've tried everything I could find here, but have had no luck. I have a form that has a db backend. When the user enters a valid user/pwd combo they are allowed to view only certain items based upon their settings. My form has three buttons (VSI Rep, Media, Dealer). I am trying to make it so that if a user only has access to the dealer info, then pressing the VSI Rep and Media buttons will do nothing. But pressing the Dealer button will bring up a bunch of stuff for them. It seems I've got everything plugged in, but can't figure out how to pass the rep, media, dealer value to the next ASP program.

Here is my script:
<SCRIPT LANGUAGE="JavaScript1.2">
function ValidForm() {
if (document.form1.username.value == "" || document.form1.password.value == "") {
alert("Please enter user name and password.");
document.form1.username.focus();
return false;
}
else
return true;
}
</SCRIPT>
<script>
function doSubmit(btn)
{
document.form1.submit.value=btn;
document.form1.submit();
}
</script>
-----------------------------------------
Here is my form:

<FORM ACTION="VTmain.asp?Option=LogIn" NAME="form1" METHOD="post" ONSUBMIT="return ValidForm();">
<input type=hidden name=submit1 value="">

<TABLE BORDER="0" BGCOLOR="#FFFFFF" CELLPADDING="2">
<TR>
<TD ALIGN="RIGHT" COLSPAN="2"><B><FONT FACE="Arial, Helvetica">Enter your User ID:</FONT></B></TD>
<TD><INPUT TYPE="TEXT" NAME="username" SIZE="12" VALUE="<%= lcType %>-<%= lcRequest %>"></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" COLSPAN="2"><FONT FACE="Arial, Helvetica"><B>Enter your Password:</B></FONT></TD>
<TD><INPUT TYPE="PASSWORD" NAME="password" SIZE="12"></TD>
</TR>
<TR>
<TD COLSPAN="3" ALIGN="CENTER">&nbsp;</TD>
</TR>
<TR>
<TD ALIGN="CENTER" COLSPAN="3">
<TABLE WIDTH="350" BORDER="0" CELLPADDING="10" CELLSPACING="0" ALIGN="CENTER">
<TR>
<TD><input type="image" NAME="submit1" SRC="images/vsi-rep.gif" onclick="doSubmit('OSR')" ></TD>
<TD><input type="image" NAME="submit1" SRC="images/media.gif" onclick="doSubmit('Media')" ></TD>
<TD><input type="image" NAME="submit1" SRC="images/dealer.gif" onclick="doSubmit('Dealer')" ></TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE></FORM>
-----------------------------

any assitance would be greatly appreciated.

Thanks, in advance!!


~ lahddah
 
Add a value attribute to the image code

Code:
<TD><input type="image" NAME="submit1" SRC="images/vsi-rep.gif" onclick="doSubmit('OSR')" value="r"></TD>
<TD><input type="image" NAME="submit1" SRC="images/media.gif" onclick="doSubmit('Media')" value="m"></TD>
<TD><input type="image" NAME="submit1" SRC="images/dealer.gif" onclick="doSubmit('Dealer')" value="d"></TD>

then on the server, after submission

Code:
myType=Request("submit1")

if myType = "d" then
   session("UserType") = "dealer"
elseif myType = "m" then
   session("UserType") = "media"
elseif myType = "r" then
   session("UserType") = "rep"
end if

'rest of your code based on UserType


Bastien

Cat, the other other white meat
 
Thanks, bastienk. But I think the problem is that the 'value' of the images doesn't pass on to the next program. (I think!) So, myRequest=Request.Form(Submit1) is always empty. Actually, I'm not sure how to tell what the value of request.form("Submit1") really is. I've tried putting it in other variables and doing a 'response.write' and I've tried doing a 'response.write' directly with 'request.form("Submit1") but nothing appears.

However if I test it (if LEN(reqest.form("Submit1")) > 0 Then lctest = "there's something here" else lctest = "nothin' doin".

When I do this test, I get the 'something there' message, but I just can't figure out what it is! (make sense?)



~ lahddah
 
PS - I wrote that last post after trying to put your previous suggestion into my code....



~ lahddah
 
was looking your code....can you see the problem?

Code:
document.form1.submit.value=btn;
 document.form1.submit();
}
</script>

 <FORM ACTION="VTmain.asp?Option=LogIn" NAME="form1" METHOD="post" ONSUBMIT="return ValidForm();"> 
<input type=hidden name=submit1 value="">

Hint: the hidden field and the assignation of the value won't work....

They aren't named the same


Bastien

Cat, the other other white meat
 
Yeah. You're right. That was one of the many variations that I've tried that didn't work (including name it that same (submit1)).

Here is my script:
<script>
function doSubmit(btn)
{
document.form1.submit1.value=btn;
document.form1.submit();
}
</script>

--------

my form call:
<FORM ACTION="VTmain.asp?Option=LogIn" NAME="form1" METHOD="post" ONSUBMIT="return ValidForm();">
<input type=hidden name=submit1 value="">
---------

and the fields:
<TR>
<TD><input type="image" NAME="submit1" SRC="images/vsi-rep.gif" onclick="doSubmit('OSR')" VALUE="r"></TD>
<TD><input type="image" NAME="submit1" SRC="images/media.gif" onclick="doSubmit('Media')" VALUE="m"></TD>
<TD><input type="image" NAME="submit1" SRC="images/dealer.gif" onclick="doSubmit('Dealer')" VALUE="d"></TD>
</TR>

-----
I've tried for so long and so many different variations that I've gotten lost. So, at this point it is probably something really simple that I'm just overlooking.

Thanks!


~ lahddah
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top