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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

redirect page with js function

Status
Not open for further replies.

zeero

Programmer
Aug 4, 2004
60
US
Greets all. How would I have a page automatically submit a function (redirect) to another jsp page?

e.g. hit the first page (html) that has a js function on it, and instead of clicking a button to submit and take you to the next page, just automatically load the page, then redirect you to the second page with the function submitting with it.
 
Well, if by "function submitting" you mean "submitting a form" and the "next page" is the value of the ACTION attribute in the FORM tag, then you merely need to:

<body onload='document.formName.submit();'>
...

Is that what you mean?

--Dave
 
hey dave, this isn't directly related to my question over on the jsp forum btw ^^

right now it's as follows:

-you go to an html page with javascript in it that does a function withe the onclick event.

-then you click a button (triggers event) which sends you to a jsp page that takes the value of the javascript.


instead of clicking a button, I would like the first html page you hit to wait X seconds then send you to a jsp page with the function sent as well. (the js sends a string to the jsp page)
 
Well, this sounds like a form-submit.

On the first page:

<body onload='waitAndSubmit();'>
<form name='form1' action='secondPage.html' method='GET'>
<input type='text' name='textField' value='Value being passed' size='30' />
</form>
</body>

The function referenced in the BODY tag's ONLOAD event is:

var X = 3; //# of seconds to wait
function waitAndSubmit()
{
setTimeout("document.form1.submit()", X*1000)
}

It probably wouldn't hurt to "escape" the value you're sending:

function waitAndSubmit()
{
document.form1.textField.value = escape(document.form1.textField.value); //replaces spaces with %20, for example
setTimeout("document.form1.submit()", X*1000)
}

If your second page is a JSP or ASP, then you can do a POST-method on your form and not worry about the escape(...) function.

'hope that helps.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top