Click to See Complete Forum and Search --> : Mix & match JS and ASP


SFF
01-20-2003, 01:04 AM
Hi!

ive just come from the ASP forums @ 4guysfromrolla.com and there befuddled with this question..so i thought i would come ask a JS genius if there is any..

the problem is i need to submit a button in a form to an ASP page after it the fields have been validated.


the problem is with the login.submit , the ASP code looks for a button called ok...but the form is not submitting it...how can i submit the button with the code?

here is the code:

<%@ Language=VBScript %>
<!--#include file="config.sf"-->

<%
'SPITS THE USER OUT IF THEY HAVE A NETSCAPE BROWSER

Dim DIMuserInfo, DIMie, DIMbrowver, DIMjs, DIMmeta
SET DIMuserInfo = Server.CreateObject("MSWC.BrowserType")

IF NOT((DIMuserInfo.Browser = "IE") OR (DIMuserInfo.version > 4)) then
response.redirect "bad.html"
END IF
SET DIMuserInfo = Nothing

'THREE ATTEMPTS ALLOWED LOGIN

IF ISEMPTY(REQUEST.FORM("ok")) THEN
SESSION("attempts") = 1
DIMmsg = "&nbsp;"
ELSE
DIM DIMfilterID, DIMfilterPW, RSLogin, DIMmsg
DIMfilterID = REPLACE(REQUEST.FORM("id"),"'", "")
DIMfilterPW = REPLACE(REQUEST.FORM("pw"),"'", "")
SET RSLogin = CONN.EXECUTE("SELECT * FROM login WHERE id = '" & DIMfilterID & "' AND PW = '" & DIMfilterPW & "';")
IF(RSLogin.EOF) THEN
Session("attempts") = SESSION("attempts") + 1
IF Session("attempts") => 4 THEN
DIMmsg = "LOGIN NOT FOUND! NO MORE ATTEMPTS ALLOWED!"
ELSE
DIMmsg = "LOGIN NOT FOUND, TRY AGAIN!"
END IF
ELSE
Session("rname") = RSLogin("Rname")
Session("name") = RSLogin("Name")
Session("loginID") = RSLogin("loginID")
Response.Redirect "intro.asp"
END IF
END IF
%>
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>&sect;h&Atilde;&ETH;&Oslash;W&yen; ƒr&euro;&Atilde;K</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="css%5Cshadowy.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/JavaScript">
<!--
function idform(VARidvalue)
{
if(VARidvalue=="name here")
{
login.id.value='';
}

}

function pwform(VARpwvalue)
{
if(VARpwvalue=="password here")
{
login.pw.value='';
}

}

function validateme(VARidValue, VARpwValue)
{

if(VARidValue=='name here')
{alert("Don't tell me you left the default 'name here' words in?!...tsk tsk tsk, you know better then that!");}
else
{
if(VARpwValue=='password here')
{alert("Don't tell me you left the default 'password here' words in?!...tsk tsk tsk, you know better then that!");}
else
{
if((VARidValue=='') || (VARidValue == null))
{
alert("You forgot your name!");
login.id.focus();
}
else
{
if((VARpwValue=='') || (VARpwValue == null))
{
alert("You forgot your password!");
login.pw.focus();
}
else
{
login.submit();
}
}
}
}

}


//-->
</script>
</head>

<body bgcolor="#000000" text="#FFFFFF" link="#0000CC" vlink="#990000" alink="#FF6600" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="5">
<tr>
<td align="center" valign="middle"><p><img src="images/SFlogo.jpg" width="475" height="105" /><br><%=DIMmsg%></p>
<%IF NOT(SESSION("attempts") => 4)THEN%>
<form action="index.asp" method="post" name="login" target="_self" id="login">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="middle"> <input name="id" type="text" id="id" value="name here" maxlength="10" onClick="idform(login.id.value)"/></td>
</tr>
<tr>
<td align="left" valign="top"> <input name="pw" type="password" id="pw" value="password here" maxlength="10" onClick="pwform(login.pw.value)" /></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><input name="ok" type="button" id="ok" value="Enter" onClick="validateme(login.id.value, login.pw.value, login.ok.value)" />
<input type="reset" name="Submit2" value="Leave" onClick="javascript: window.location='http://hawkeye/'" /></td>
</tr>
</table>
</form>
<%ELSE%>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<%END IF%>
<font size="-2" face="Times New Roman, Arial, Times, sans-serif">Designed
for MS Internet Explorer 5.00.2919.63.07IC or Better; If you don't like it, tough.<br />
Enter this site at your own risk!</font>
</td>
</tr>
</table>
</body>
</html>
<!--#include file="error.sf"--

khalidali63
01-20-2003, 01:21 AM
did u mean that <input type="button" name="submit">

and when user clicks on this button the javascript button submits the form?

SFF
01-20-2003, 01:29 AM
Dear khalidali

thanks for replying your the first one to attempt this..lol

no that is not what i meant

when input name="ok" type="button"
is pressed, it passes the form values to a JS function which validates them.

when the validation has been completed, the form is submitted.

then the ASP file looks through the form to see if the input name="ok" type="button" is in the form, and then processes the rest of the page..

but what i need is to make the asp page realise that the button is there when the JS submits the page.


this code works with a "submit" button type...but i cannot use a submit button because of the validation..if i used the submit button, the form is sumitted and validated at the same time.


SF

khalidali63
01-20-2003, 01:34 AM
Oh..ok..I thought your question had to do with JavaScript.
How ASP reads form...well you better try ur luck in ASP forums..

Oh by the way you should have been able to use submit type without any problems and yet validate the form as well.

Khalid

SFF
01-20-2003, 01:37 AM
Sorry i might not have made myself clear,

it is about javascript

next post coming in about 1 tick

SFF
01-20-2003, 01:40 AM
how do i pass the form values to the function when they press the submit button, yet not have the page submit until the form has been validated, and cancel the submit button if the form is incorrect?

i thought of an onblur, but that doesn't work, because if a user just surfs along and then clicks the submit button..the form will submit....?

any ideas?

khalidali63
01-20-2003, 01:57 AM
ok got it ..easy stuff

SFF
01-20-2003, 02:00 AM
lol easy stuff you say....

* I feel like an insignificant worm now*

lol

khalidali63
01-20-2003, 02:05 AM
My fault sorry,did not come out right.

Anyhow.
here is the sample code.

Khalid


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-5"></meta>
<meta name="Author" content="Khalid Ali"></meta>
<title>Untitled</title>
<script type="text/javascript">
/**************************************************************************************
Author : Khalid Ali
Date :
Version : 1.1
Company : NetTech
Description :
***************************************************************************************/
function validateForm(){
var frm = document.form1;
for(n=0;n<frm.length;n++){
if(frm[n].type=="text" && frm[n].value==""){
alert("Please do not leave a text field empty.");
frm[n].focus();
return false;
}else if(frm[n].type=="checkbox" && frm[n].checked==false){
alert("Please do not leave a checkbox unchecked.");
frm[n].focus();
return false;
}
}
return true;
}

</script>
</head>

<body>
<form name="form1" action="yourAspPage" onsubmit="return validateForm();" method="post">
<input type="Text" name="t1"/><br/>
<input type="Text" name="t2"/><br/>
<input type="Checkbox" name="cb1"/><br/>
<input type="Submit"/>
</form>


</body>
</html>

SFF
01-20-2003, 02:10 AM
many many thank you's khalidali!

i really appreciate what you have done..

SF