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

Javascript Redirect in ASP 1

Status
Not open for further replies.

DrSeussFreak

Programmer
Feb 16, 2007
149
US
I am working on a form in ASP, and I am trying to integrate a javascript redirect option for an onclick event on a button.

Below is the javascript, but how do I get the button to activate the script?

Code:
</script>
<script language="javascript">
function redirect("page.asp") { location = "page.asp"; }
</script>
 
You draw it on the webpage with HTML, then on the onclick handler of the button, call the function redirect:

Code:
<input type="button" value="Redirect" onclick="redirect('[!]<%=fileName%>[/!]') />

I saw you asking questions in the ASP forum about this, so I assume the file name is in an ASP variable. This is how you'd do that.


[monkey][snake] <.
 
Ok, so code is as follows

Code:
<script language="javascript">
function redirect("ViewProductInfoQSResults.asp") { location = "ViewProductInfoQSResults.asp"; }
</script>
&
Code:
<input type="button" name="btnSearch" value="Submit" onclick="redirect('<%="ViewProductInfoQSResults.asp"%>')">
 
No, not exactly. If you already know the page you need to go to, then you don't have to specify it anywhere except in your window.location statement. As a matter of fact, if that's all the function is going to do, just do the redirect inline with the button.

Erase ALL this code:
Code:
<script language="javascript">
function redirect() { location = "ViewProductInfoQSResults.asp"; }
</script>

On your button, type this:
Code:
<input type="button" name="btnSearch" value="Submit" onclick="window.location('ViewProductInfoQSResults.asp')">


[monkey][snake] <.
 
Brainfart I'm sorry it's


[!]window.location = 'ViewProductInfoQSResults.asp'[/!]

Tested


[monkey][snake] <.
 
1 last question, since it is not actually using the form submit, how do I pass the variable located in the text box?
 
If you want to pass the variable in the text box, you have to submit a form.

On your page, you should put a form with action = 'ViewProductInfoQSResults.asp'

I'll draw you up a quick skeleton:

Code:
<form id="frm" action="ViewProductInfoQSResults.asp" method="post">
   <input name="textBox" type="text" value="blah" />
   <input type="button" name="btnSearch" value="Submit" onclick="document.getElementById('frm').submit()">

</form>

This small example will submit the form when you click on your button. When the form submits, it will redirect you to ViewProductInfoQSResults.asp. Since you submit the form, you will be able to retrieve the info from that textbox since it was in the form.




[monkey][snake] <.
 
Code:
<select name="slProducts" size="1" onChange="submit();" onBlur="submit();"></select>

Because of this code, it utilizes the form submit for reloading the page. Because of this, I can not change the action to the other page.

Any other suggestions
 
Code:
<select name="slProducts" size="1" onChange="[!]document.forms['formName'].action = 'newpage.asp';[/!]submit();" onBlur="submit();"></select>

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top