Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submit form using a href problem

Status
Not open for further replies.

dessie1981

Programmer
Joined
May 9, 2006
Messages
116
Location
GB
Hi Everyone,

Im having some trouble submiting a form using a href, am new to javascript and could use some help
This is what i am trying and doh its just not working

<html>
<head>
<title>
form test
</title>
</head>
<body>
<script type="text/javascript">
<!--
formSubmit()
{
documents.myform.submit();
}
//-->
</script>
<form name="myform" method="post">
<input type="text" name="purchaseid">
</form>
<p>
<A HREF="formtest2.php" ONCLICK="formSubmit()">confirm</A>
</p>
</body>
</html>


this is how im handleing the data

<?
echo $_POST['purchaseid'];
?>

Any help would be much appreciated

Des
 
><A HREF="formtest2.php" ONCLICK="formSubmit()">confirm</A>
[tt]<A HREF="[blue]javascript:formSubmit()[/blue]">confirm</A>

formSubmit()
{
[blue]document.myform.action="formtest2.php";[/blue]
documen[highlight]t[/highlight].myform.submit();
}
[/tt]
 
Thanks Tsuji,

But the href is not navigating anywhere with this solution, any more ideas?

Dessie
 
>But the href is not navigating anywhere with this solution, any more ideas?
Where do you want to submit? There is no action attribute in your form?
 
i am trying to get the browser to navigate to formtest2.php also.
Have tried putting the action attribute in the form and still not working.
I though that the javascript function takes care of the action attribute.

<html>
<head>
<title>
form test
</title>
</head>
<body>
<script type="text/javascript">
<!--
formSubmit()
{
document.myform.action="formtest2.php";
document.myform.submit();
}
//-->
</script>
<form name="myform" method="post" action="formtest2.php">
<input type="text" name="purchaseid">
</form>
<p>
<A HREF="javascript:formSubmit()">confirm</A>
</p>
</body>
</html>
 
If I do not get what you want, that's normal and that happens. If you do not know what you want, it gets me thinking.

Now you add both place an action. What for? Either one would suffice not? Is it that you want to submit the form to formtest2.php and also want to "navigate" to formtest2.php without any request variable set. (That's somehow curious though not impossible.)
[tt]
<html>
<head>
<title>
form test
</title>
</head>
<body>
<script type="text/javascript">
<!--
formSubmit()
{
document.myform.submit();
}
//-->
</script>
<form name="myform" method="post" action="formtest2.php">
<input type="text" name="purchaseid">
</form>
<p>
<A HREF="formtest2.php" target="_blank" onclick="formSubmit()">confirm</A>
</p>
<!-- "navigate" to somewhere -->
<p>
<A HREF=" target="_blank" onclick="formSubmit()">confirm & navigate to somewhere else</A>
</p>

</body>
</html>
[/tt]
 
Amendment

I forgot to add the missing function keyword in your original script!
[tt]

<html>
<head>
<title>
form test
</title>
</head>
<body>
<script type="text/javascript">
<!--
[red]function[/red] formSubmit()
{
document.myform.submit();
}
//-->
</script>
<form name="myform" method="post" action="formtest2.php">
<input type="text" name="purchaseid">
</form>
<p>
<A HREF="formtest2.php" target="_blank" onclick="formSubmit()">confirm</A>
</p>
<!-- "navigate" to somewhere -->
<p>
<A HREF=" target="_blank" onclick="formSubmit()">confirm & navigate to somewhere else</A>
</p>

</body>
</html>
[/tt]
 
Yes i need to send the parameter and also navigate to the same place, as in the script where i will be using this piece of code is a confirmation for a shopping cart and i need the user to enter a purchase id. It needs to be a href link in order to conform with the style of the page. The data on the confirmation page gets written to a file and also a mail.

I tried the code that you gave me above and it has some weird effects. When i hit the confirm link to submit, a new page is opening giving the undefined notice for "purchaseid" yet on the original in the orig tab i have the result echo'd fine.
Im using firefox btw.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top