how do i pass dynamic variable into javascript from input box?

S

sajoca3

thanks for your help

depending on a input, I need to change var
checkcaptcha=(t/f)

if true then default else pass????

<SCRIPT LANGUAGE="JavaScript">

function SubmitForm()

{
var CheckCAPTCHA=true
if (CheckCAPTCHA==true)
{
document.frmLogin.action = "default.asp";
document.frmLogin.submit();
}
else
{
document.frmLogin.action = "pass.asp";
document.frmLogin.submit();

}
}
</SCRIPT>
 
T

Tom Cole

Forgive me if I misunderstand...

Let's say the input field in question has an id attribute of
"checkCaptcha" i.e.

<input type="text" id="checkCaptcha"/>

Then you would retrieve the value of the input by calling:

var captcha = document.getElementById("checkCaptcha").value;

You would then update your CAPTCHA variable using whatever logic you
need:

if (captcha == "SomeValueThatMeansYes") {
CheckCAPTCHA = true;
}
else {
CheckCAPTCHA = false;
}

or you could opt for the form:

var CheckCAPTCHA = (captcha == "SomeValueThatMeansYes") ;

Of course if this check is the only time in your method that you will
actually use the value, then you don't need to actually assign it to a
variable at all, you could use the actual == as your boolean.

So you would have something like:

function SubmitForm() {

var captcha = document.getElementById("checkCaptcha").value;

if (captcha = "SomeValueThatMeansYes") {
document.frmLogin.action = "default.asp";
document.frmLogin.submit();
}
else {
document.frmLogin.action = "pass.asp";
document.frmLogin.submit();
}

}

You would of course replace "checkCaptcha" with the id of your input
field and replace "SomeValueThatMeansYes" with the value you would
expect the input to have if you wanted to check captcha.

BTW...it's not recommended that you access the frmLogin element in the
global scope like you do. You should either assign an id to your form
element and access through document.getElementById("myFormId"), or
assign it a name and access through the
document.getElementsByName("myFormName")[0] array or use
document.forms["myFormName"]. You could also go crazy and access via
the document.getElementsByTagName("form")["myFormName"] array. You
should also update your script tag to use the type attribute, not the
LANGUAGE attribute (<script type="text/javascript">).

HTH.
 
T

Tom Cole

Sorry fix my original snippet from assignment to comparison:

function SubmitForm() {

var captcha = document.getElementById("checkCaptcha").value;

if (captcha == "SomeValueThatMeansYes") {
document.frmLogin.action = "default.asp";
document.frmLogin.submit();
}
else {
document.frmLogin.action = "pass.asp";
document.frmLogin.submit();
}

}

Forgive me if I misunderstand...

Let's say the input field in question has an id attribute of
"checkCaptcha" i.e.

<input type="text" id="checkCaptcha"/>

Then you would retrieve the value of the input by calling:

var captcha = document.getElementById("checkCaptcha").value;

You would then update your CAPTCHA variable using whatever logic you
need:

if (captcha == "SomeValueThatMeansYes") {
    CheckCAPTCHA = true;}

else {
    CheckCAPTCHA = false;

}

or you could opt for the form:

var CheckCAPTCHA = (captcha == "SomeValueThatMeansYes") ;

Of course if this check is the only time in your method that you will
actually use the value, then you don't need to actually assign it to a
variable at all, you could use the actual == as your boolean.

So you would have something like:

function SubmitForm() {

    var captcha = document.getElementById("checkCaptcha").value;

    if (captcha = "SomeValueThatMeansYes") {
        document.frmLogin.action = "default.asp";
        document.frmLogin.submit();
    }
    else {
        document.frmLogin.action = "pass.asp";
        document.frmLogin.submit();
    }

}

You would of course replace "checkCaptcha" with the id of your input
field and replace "SomeValueThatMeansYes" with the value you would
expect the input to have if you wanted to check captcha.

BTW...it's not recommended that you access the frmLogin element in the
global scope like you do. You should either assign an id to your form
element and access through document.getElementById("myFormId"), or
assign it a name and access through the
document.getElementsByName("myFormName")[0] array or use
document.forms["myFormName"]. You could also go crazy and access via
the document.getElementsByTagName("form")["myFormName"] array. You
should also update your script tag to use the type attribute, not the
LANGUAGE attribute (<script type="text/javascript">).

HTH.

thanks for your help
depending on a input, I need to change var
checkcaptcha=(t/f)
if true then default else pass????
<SCRIPT LANGUAGE="JavaScript">
function SubmitForm()
{
var CheckCAPTCHA=true
if (CheckCAPTCHA==true)
{
        document.frmLogin.action = "default.asp";
        document.frmLogin.submit();}
else
{
        document.frmLogin.action = "pass.asp";
        document.frmLogin.submit();

</SCRIPT>
 
S

sajoca3

Sorry fix my original snippet from assignment to comparison:

function SubmitForm() {

var captcha = document.getElementById("checkCaptcha").value;

if (captcha == "SomeValueThatMeansYes") {
document.frmLogin.action = "default.asp";
document.frmLogin.submit();
}
else {
document.frmLogin.action = "pass.asp";
document.frmLogin.submit();
}

}

Forgive me if I misunderstand...
Let's say the input field in question has an id attribute of
"checkCaptcha" i.e.
<input type="text" id="checkCaptcha"/>
Then you would retrieve the value of the input by calling:
var captcha = document.getElementById("checkCaptcha").value;
You would then update your CAPTCHA variable using whatever logic you
need:
if (captcha == "SomeValueThatMeansYes") {
CheckCAPTCHA = true;}
else {
CheckCAPTCHA = false;

or you could opt for the form:
var CheckCAPTCHA = (captcha == "SomeValueThatMeansYes") ;
Of course if this check is the only time in your method that you will
actually use the value, then you don't need to actually assign it to a
variable at all, you could use the actual == as your boolean.
So you would have something like:
function SubmitForm() {
var captcha = document.getElementById("checkCaptcha").value;
if (captcha = "SomeValueThatMeansYes") {
document.frmLogin.action = "default.asp";
document.frmLogin.submit();
}
else {
document.frmLogin.action = "pass.asp";
document.frmLogin.submit();
}

You would of course replace "checkCaptcha" with the id of your input
field and replace "SomeValueThatMeansYes" with the value you would
expect the input to have if you wanted to check captcha.
BTW...it's not recommended that you access the frmLogin element in the
global scope like you do. You should either assign an id to your form
element and access through document.getElementById("myFormId"), or
assign it a name and access through the
document.getElementsByName("myFormName")[0] array or use
document.forms["myFormName"]. You could also go crazy and access via
the document.getElementsByTagName("form")["myFormName"] array. You
should also update your script tag to use the type attribute, not the
LANGUAGE attribute (<script type="text/javascript">).

On Mar 14, 2:54 pm, (e-mail address removed) wrote:
thanks for your help
depending on a input, I need to change var
checkcaptcha=(t/f)
if true then default else pass????
<SCRIPT LANGUAGE="JavaScript">
function SubmitForm()
{
var CheckCAPTCHA=true
if (CheckCAPTCHA==true)
{
document.frmLogin.action = "default.asp";
document.frmLogin.submit();}
else
{
document.frmLogin.action = "pass.asp";
document.frmLogin.submit();
}
}
</SCRIPT>

Thanks, Tom, your script helps, I don't know how to pass in right
variable to work with my default page

if captcha is type right page will go to pass.asp or stay default page
with wrong captcha.

***************default.asp**************
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1254"%>
<%
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
%>
<%
Function CheckCAPTCHA(valCAPTCHA)
SessionCAPTCHA = Trim(Session("CAPTCHA"))
Session("CAPTCHA") = vbNullString
if Len(SessionCAPTCHA) < 1 then
CheckCAPTCHA = False
exit function
end if
if CStr(SessionCAPTCHA) = CStr(valCAPTCHA) then
CheckCAPTCHA = True
else
CheckCAPTCHA = False
end if
End Function
%>
<!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>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-9" />
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<title>ASP Security Image Generator (CAPTCHA) v2.0</title>
</head>

<body>
<form id="frmLogin" name="frmLogin" method="post"
action="default.asp">
<table width="350" height="187" border="1" align="center">
<tr>
<td width="182"><img src="aspcaptcha.asp" alt="This Is CAPTCHA
Image" width="86" height="21" /></td>
</tr>
<%
if Request.ServerVariables("REQUEST_METHOD") = "POST" then
strCAPTCHA = Trim(Request.Form("strCAPTCHA"))
if CheckCAPTCHA(strCAPTCHA) <> true then
%>
<tr>
<td height="37" colspan="2" align="center"><b
style="color:#FF0000">Please Retry.</b></td>
</tr>
<%
end if
end if
%>
<tr>
<td height="66">Write the characters in the image above</td>
<td><input name="strCAPTCHA" type="text" id="strCAPTCHA"
maxlength="8" /></td>

</tr>
<tr>
<td height="37" colspan="2" align="center">
<input type="button" name="cmdView" id="cmdView" value="View"
onclick="SubmitForm();">
</tr>
</table>
</form>
</body>
</html>
<SCRIPT LANGUAGE="JavaScript">
***********default.asp*************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top