I posted this the other day. I don't know why people use "location". This is
how it should be done:
<a href="javascript:myFormFunction('/servlet/ServletName','formName')>text
or image</a>
Then in the head of the document (or js include) put a function something
like:
<script>
function myFormFunction(theAction, theForm) {
// custom cross platform function that gets an object..
// create your own or take Dreamweaver's - MM_findObj or something like
that
myFormObj = getObject(theForm) ;
// set the action
myFormObj.action = theAction;
myForm.submit();
}
</script>
----- Original Message -----
From: "Bart R Schroder" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, February 16, 2001 7:29 AM
Subject: Question: Call to Servlet (that doesn't generate HTML) from
> Hi Everybody,
>
> Scenario:
> User enters input into <form> page:
>
> <form name="form1" action="" onsubmit="submitclick()">
> <input type="text" name="user" value="">
> <input type="submit" name="submit" value="submit">
>
> JavaScript (located at bottom of this <form> page) tests:
>
> <script>
> {
> re1 = /\s/;
>
> var user = document.form1.user.value;
>
> if(user == null || user.search(re1) != -1)
> {
> location.reload();
> }
> else
> {
> window.location = \"/servlet/authenticateLogin?user=\" +
> user;
>
> parent.form.action = "../servlet/authenticateLogin";
> }
>
> }
> </script>
>
> The authenticateLogin servlet (doesn't generate HTML) acts as a
> traffic cop; testing the values sent to it from the JavaScript (mentioned
> above), and then res.sendRedirect("html/someOtherURL").
>
> Q: Why is it that neither of these manage to call the
authenticateLogin
> servlet?
>
> parent.form.method = "POST";
> parent.form.action = "../servlet/authenticateLogin";
>
> form.method = "POST";
> form.action = "../servlet/authenticateLogin";
>
> Q: Do I need to set the <form> 'action' attribute to a literal value,
null
> (ie, ""), or do I need to make it a variable. If variable, then could you
tell
> me the exact syntax, as I can't find an example to save my life.
>
>
>
> Thanks,
>
> Bart
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html