/    Sign up×
Community /Pin to ProfileBookmark

dynamically assigning servletURL in Form Tag

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: “......AppDirServletName”) properly when the Form is submitted?

Please Help.
Many Thanks,
K.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliOct 12.2003 — 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
Copy linkTweet thisAlerts:
@JdvlprauthorOct 12.2003 — Thanks a lot Khalid, I just tried it in one of the cases and it worked beautifully.

Thanks again.

K.
Copy linkTweet thisAlerts:
@Khalid_AliOct 12.2003 — ? My pleasure
×

Success!

Help @Jdvlpr spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...