RobG wrote:
Navillus wrote: Navillus wrote:
Hey gang,
I have a login form that is empty by default, but can be filled with
values from a previous form:
<input type=text maxlength="40" size="40" name="user" value="`usr`">
<input type=password maxlength="8" name="password" value="`pss`">
where usr and pss are sent from the previous form.
Then you have minimal security.
I'd like to make a javascript function (I assume this is easy in
javascript) that automatically submits the form when usr and pss exist.
How would this be done?
Building on my previous post, I've looked up this much so far:
In the header, I put:
<head>
<script language="javascript">
The language attribute is deprecated, type is required.
function autoSubmit()
{
document.form.submit();
You have a form named 'form'?
}
</script>
</head>
and then after the form, in the document, I put this:
<script language="JavaScript">
if (`usr`)
That will always be true. Taken literally, you are asking if 'usr' is
not undefined, which it isn't so the test returns true.
Presuming that 'usr' is your shorthand for a reference to the value of
the input named 'user', then (based on the posted HTML) it will have a
value of - 'usr' - (quotes included) and so that will return true too.
{
autoSubmit();
}
</script>
Now, when usr is present, it should trigger the if statement to be
No, it will always be true so it will try to submit the form immediately
regardless.
true. And it is definatly showing up correctly; that is, when usr is
absent, the if statement is empty, but if usr is present, the if
statement is filled. But for some reason it isn't redirecting. Yikes!
What you have shown is an attempt to call the submit method of a form
with name/id of 'form'.
You haven't shown the actual form, how you try to get and insert values
for 'usr' or 'pss', or even what it is supposed to do onsubmit (what is
the value of the action attribute? does it use POST or GET?) so a
statement about what might happen when the submit method is called is
speculation.
--
Rob
Here's the jist of what I got so far. Something is still tripping it up
so it can't submit:
<script language="JavaScript">
function savecookie()
{
/* save the values of user and password of the form input
(document.form.elementname) in the cookie */
var url = "/sap/its/iacproject/select_premises.html";
var nextyear = new Date();
nextyear.setFullYear(nextyear.getFullYear() + 1);
document.cookie = 'password= '+ document.Login.password.value +
'# expires='+ nextyear.toGMTString() +'; path= /';
document.cookie = 'user= '+ document.Login.user.value + ';
expires=' + nextyear.toGMTString() +'; path= /';
}
function autoSubmit(){
document.Login.submit();
}
</script>
</head>
<body `SAP_BodyAttributes()` onload="`SAP_OnloadJavaScript()`">
<form name="Login" action="">
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<br>
<br>
<tr>
<td width=5%></td>
<td>
<table border=0 cellpadding=2 cellspacing=2>
<tr>
<td align=right class=label>`#LoginID`
</td>
<td align=left>
<input type=text maxlength="40" size="40" name="user"
value="`usr`">
</td>
</tr>
<tr>
<td align=right class=label>`#Password`
</td>
<td align=left>
<input type=password maxlength="8" name="password" value="`pss`">
</td>
</tr>
<tr>
<td></td>
<td>
<input type=image name="~OkCode(LGON)"
SRC="`mimeURL(~name="button/login.gif")`" border=0
onclick="savecookie();">
</td>
</tr>
</table>
`if (~messageline != "")`
<table border=0>
<tr>
<td align=center class=message>`~messageline`
</td>
</tr>
</table>
`end`
</td>
</tr>
</form>
<script language="JavaScript">
var testUser = `usr`;
if (testUser != "")
{
savecookie(); <-- not sure if I should call this function, which
the normal form seems to do
autoSubmit(); <-- or this guy right here, neither seem to work
}
</script>
<script> document.Login.user.focus(); </script>
<p>
</p>
</body>
</html>
Now, there's some wierd SAP variable stuff in there, but trust me, when
the previous form sends the variable 'usr', calling `usr` puts it in
there correctly. It doesn't seem to matter though. I've tried like 5
different ways to test to see if usr exists, and none of them seem to
work. In fact, even if I just do something like if (1), it still won't
automatically submit. Well, it did once, but only when there wasn't a
value of usr. I'm thinking something like the <script>
document.Login.user.focus(); </script> is preventing it from
auto-submitting. I dont know. All help is appreciated. Thanks