General discussion

Locked

Javascript, submit a form from a link...

By ae_maillist ·
I would like to submit a form from a link.

I tried something like this...

a HREF="/asp/katalog.asp?action=save&page=3 target="_self" language="javascript"
onClick="document.form1.submit();">3</a>

but it does not do it...

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Javascript, submit a form from a link...

by Alesandrial In reply to Javascript, submit a form ...

Try this:

<A HREF="javascript:document.form1.submit();">3</A>

Collapse -

Javascript, submit a form from a link...

by ae_maillist In reply to Javascript, submit a form ...

Poster rated this answer

Collapse -

Javascript, submit a form from a link...

by juanja In reply to Javascript, submit a form ...

The only thing what you propose is going to do is go to the other page. What you need to do is include the values of the link as fields of the form, and then retrieve them before you check the stage of the process:

you replace this: action=save&page=3

for this:

<input type="hidden" name="action" value="save">
<input type="hidden" name="page" value="3">

<a href="/asp/katalog.asp" target="_self" onClick="document.form1.submit();">3</a>

to check the stage of the process get thesevariables at the beginning of the page:

action=request.form("action")
page=request.form("page")

if action="save" then........

Hope this helps,
bye

Collapse -

Javascript, submit a form from a link...

by ae_maillist In reply to Javascript, submit a form ...

Poster rated this answer

Collapse -

Javascript, submit a form from a link...

by fpc/ns In reply to Javascript, submit a form ...

Depending on whether you need t osubmit a form via the GET method or the POST method there are different ways to do it.

To submit via a GET method you can simply write a query string into the link. Something like as follows:
<a href="/asp/katalog.asp?action=save&page=3">Submit Form</a>

Because unless otherwise specified all pages are loaded via the GET method this is simply sending the same data a form would have, but is done with a link/query string.

If the data must be sent via thePOST method the best way to do it is with hidden form elements and a simple javascript function. See the example below:

<html>
<head>
</head>
<body>

<a href="javascript:formSubmit('save','3')">Submit Form</a>

<form name="form1" action="/asp/katalog.asp" method="post">
<input type="hidden" name="action" value="">
<input type="hidden" name="page" value="">
</form>

<script language="javascript">

function formSubmit(action,page)
{
document.forms("form1").elements("action").value = action;
document.forms("form1").elements("page").value = page;

document.forms("form1").submit()
}

</script>

</body>
</html>

Collapse -

Javascript, submit a form from a link...

by ae_maillist In reply to Javascript, submit a form ...

Yes! I understand now...
Thanks!

Collapse -

Javascript, submit a form from a link...

by ae_maillist In reply to Javascript, submit a form ...

This question was closed by the author

Back to Web Development Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums