Alright, I've tried everything I could think of, but I just can't get this to work for me.
How can I use Javascript to both redirect the browser and submit a form when a button is pressed?
Printable View
Alright, I've tried everything I could think of, but I just can't get this to work for me.
How can I use Javascript to both redirect the browser and submit a form when a button is pressed?
Well, it depends. The easiest way to do it would to just use regular html and the action property to submit the form, and then have the file that you submit the form data to redirect the user, if you wanted javascript to do both, you could accomplish this with a function.
Another way that you could do it is to do something like this:
< input type="submit" value="submit" onClick="reditect();" >
since the type is a submit button, it will automatically submit the form, then all you have to do is call the redirect function to finish off the job.
I hope that helps, if you need more help, i could give a sample.
I did that, here's what I have:
Between the header tags:
Then in the form:Code:<SCRIPT LANGUAGE="Javascript">
<!--
function Clicked()
{
location.href="http://www.olemac.net/~hutch"
}
-->
</SCRIPT>
What am I doing wrong?Code:code...
<input type="submit" value="Submit" OnClick="Clicked();">
code...
you are on the right track. I am assuming that what you are having problems with is the URL redirection.
Remember that location is a property of the window, so write it like this:
also, if you want to simplify it even more, you can eliminate the function, and simply put the URL redirect within the onclick itself, like this:Code:
window.location.href='your url';
i hope that helps...Code:
onClick="window.location.href='your url'";
If you have any questions let me know
My submitbutton now contains:
Still won't work though...Code:<input type="submit" value="Submit" OnClick="window.location.href='http://www.olemac.net/~hutch';">
what doesn't work? could you explain a little more?
Ok, here's the really in-depth, nothing left out description:
I have a feedback form, and when the user clicks on it it mails the contents directly to me. But I keep getting multiple emails because people don't know for sure that the form sent. Therefore I need something that will redirect them to a "Thank you" page when they click the button. I once found something that would do this but it wouldn't submit the form so I need some way to do both.
Are you having problems getting it to work in NN? Another thing that you may want to try is the onSubmit which can be used in the form tag.
Code:
<form onSubmit="myfunction()" method="post">
Could it have to do with the location of the semicolon ";"?
what? after the window.location="whatever"? No that wouldn't matter.