I have a very weired problem (which is not easy to describe.. but I'll do my best):
I have a html page with several forms , only one of the got the action="ComputeAndReturn" and the other forms got only name="" tag...

the problem is that after i submit the form with the action , and than after a computatioon it returns to the original page, now... if i will submit any of the forms without the action=...

they will act as if they were defined action="ComputeAndReturn" (altho they are not!)

Now... if they were defined from the first time with action="anything", and than i would submit the form with action="ComputeAndReturn" this problem would not appear (the other forms will keep their action="anything" and would not "imitate" the action="ComputeAndReturn" to them selfs...

any ideas how can i keep my forms without action="" , cause all i need them to do is be submitted to pass the submitted value to other form inside that page....

it looks something like this...

function go()
{
document.one.submit();
}

 function gogo()
{
document.two.submit();
}

 function gogogo()
{
document.three.submit();
}

<form name="one" >
<select name="oneone" id="oneone" onchange="go()">
</select>
</form>    

<form name="two" >
<select name="twotwo" id="twotwo" onchange="gogo()">
</select>
</form>    

<form name="three" >
<select name="threethree" id="threethree" onchange="gogogo()">
</select>
</form>    


<form name="four" action="ComputeAndReturn" >
<input type="submit" value="Add" name="Add" />
</form>

thanks ahead...

Daniel

Dani AI

Generated

The behavior you describe (one real form submit “tainting” the others after you return from the servlet) is a symptom of how the page or the browser is resolving missing/relative form targets after navigation. Several replies here tried dummy actions or keeping everything in one form (, , , ); those are valid directions, but here are two practical, low-risk fixes that avoid guessing which browser quirk or server response is responsible and let you keep the small, actionless forms you like.

Make the action explicit right before submitting

  • Keep the forms with no hard-coded action in the HTML, but set the form’s action in JS immediately before submit. That guarantees the submit goes where you intend without changing the markup long-term.
<script>
function submitNamedForm(name, url) {
  var f = document.forms[name];
  f.action = url || '';   // set explicit target ('' posts to current document)
  f.submit();
}
</script>

Use AJAX for the ComputeAndReturn call (recommended if you need the servlet’s response)

  • Post the data with fetch/XHR and inject the returned fragment into the page. No navigation, no global action confusion, and you can display the returned HTML directly.
<script>
function postAjax(formName, url, targetId) {
  fetch(url, { method: 'POST', body: new FormData(document.forms[formName]) })
    .then(r => r.text()).then(html => document.getElementById(targetId).innerHTML = html);
}
</script>

Quick troubleshooting checklist

  • After the servlet returns, inspect the DOM (devtools) to see whether a <base> tag or changed form actions are present.
  • Avoid naming form controls submit (it can shadow the form’s submit method in some browsers).
  • If you must, consolidate server logic so a single endpoint handles the arbitration (server-side fixes are the most robust).

Either explicit-per-submit actions or an AJAX call will let you keep simple forms in the HTML while controlling exactly where each submit goes.

Recommended Answers

All 8 Replies

hi
i am not getting same problem as you are getting as i tried, any way you try to put action="#"
hope it will help..!

I did tried action="#" , but it doesn't change anything... still the other forms tries to act as if they were defined with action="ComputeAndReturn"

i know that a part of the blame that this all happening is of ComputeAndReturn which is a servlet that returns something that messing all that html... but i'm looking for a solution that i will be able to apply on the html side only...

any other ideas?

instead of calling ComputeAndReturn directly can't you call a jsp file there you will take care of calling ComputeAndReturn.
you can also have hidden field on all the form with same name and at jsp file you can check the value of hidden field and on the basis of perform correct action.

thx 4 the suggestion ,but it doesn't fit my needs , cause i need to receive some data back from the servlet and to show it ....

I use action=none when I don't want any submission.

form.submit() causes a form submit irrespective of whether that form has been assigned a real or dummy action. Plus on a page at a time only one form can be submitted. The best way here would be to rethink your design and encapsulate all the elements in the same form and perform the arbitration logic at the server itself.

action=none doesn't work also... after first form submitting of the "problematic form" all other forms starts to behave like it also.....

action="javascript:void(0);"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.