Click to See Complete Forum and Search --> : dynamically assigning servletURL in Form Tag


Jdvlpr
10-11-2003, 08:12 PM
Please Help...

I need to assign a servlet URL dynamically in the ACTION= inside the FORM Tag.

I have a javascript function getServletURL() which returns a string specifying the URL to a java servlet like this:

function getServlet() {
var servletURL;
.
.code to determine servlet here...
.
return(servletURL);
}

And the Form tag is :

<FORM id="form1" Name="form1" Action="javascript:getServletURL()" method=post>

When the form is submitted, the servlet URL string is displayed in a blank HTML page as a regular character string. Nothing else is on that page.

If the Form tag is changed to :
<FORM id="form1" Name="form1" Action="getServletURL()" method=post>

then I get a "HTTP status 404" and it tried to access "getServlet()" under the same directory / URL as the current web page.

What am I doing wrong? How do I make it take the servlet URL (for example: "..\..\..\AppDir\ServletName") properly when the Form is submitted?

Please Help.
Many Thanks,
K.

Khalid Ali
10-11-2003, 11:13 PM
using javascript in action attribute as a protocol identifier is not the suitable thing to do.
The best option for you to be is update the action in the functionsomethiong like below

function getServlet() {
var servletURL;
.
.code to determine servlet here...
.
document.getElementById("form1").action = servletURL;
}

better make action="" in the form element

Jdvlpr
10-11-2003, 11:29 PM
Thanks a lot Khalid, I just tried it in one of the cases and it worked beautifully.

Thanks again.
K.

Khalid Ali
10-11-2003, 11:33 PM
:) My pleasure