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

Input field problem 1

Status
Not open for further replies.

ptuck

MIS
Aug 8, 2003
130
0
0
US
I have the following input field that I need to redirect to the parent window. Can I do this from the value field?

<input type="hidden" name="Redirect"value="
The code I have now is redirecting the page, but it is opening the the whole site in the frame, so I now have two frames going. The other problem is I need to pass the value to our email form, so I am not sure that I can use any JavaScript.

Thanks for the help,
Paul
 
Paul,

How are you redirecting? How are you calling this redirect? Can you post some of your code? That would help troubleshoot.

J~
 
I cannot confidently, from your question, decipher what the heck you're trying to do... but, my best guess is that you're processing the value of the "Redirect" field to choose where to send your user after processing some other fields.

You CAN'T target the "parent" or "top" object in ASP, because the VBScript is running on the server and doesn't know squat about your client's window-state.

A quick-n-dirty solution, if my prior guesses are anywhere near correct, would be to have ASP create a real short HTML page that includes a javascript-style "redirect"... like so:

Code:
<%dim REDIR : REDIR = Request.Form("Redirect")%>
<html><head></head>
<body onload="top.location.href='<%=REDIR%>';">
  if you have javascript enabled in your browser, 
  you shouldn't be here long enough to read this message...
</body>
</html>

Javascript has access to almost all your client's window attributes. Handy.
 
Let me try again. I am passing values in a form (which is really just html) to our company email form (this will email a confirmation to the user). Of course, there are certian fields tha I have to pass to the form one being where to redirct the user after the email has been sent. The problem I have is I am not sure how to pass the value of the parent window in the following statement (which is the actual code) <input type="hidden" name="Redirect"value=" I am assuming the email form (which is an ASP page) is going to take the value from the redirect field and use it in the Response.Redirect statement, but this is just a guess since I cannot look at the code of the form. Since I am already in the frame, when I just pass the value of the main page of the site it just opens the site again inside the frame. So I have LeftNav, Top and then another LeftNav and Top. I am almost confused, but I hope this helps some.

Thanks for your help,
Paul
 
o.k
when u submit to the ASP page submit the entire page rather thatn one of the frames.
this can be done by:
document.FormName.target="_top"

the entire frame will submit.
now in the ASP page redirect back to the homepage.html...

Known is handfull, Unknown is worldfull
 
hey this can also be done:
<form ..... target="_top">

Known is handfull, Unknown is worldfull
 
vbkris - I need this to work from an input tage. I need to set the value of the <input type="hidden" value="home.page.htm". Can I set the value of the hidden field to value="target="_top"
 
Just put this in the <head> section of your html :
Code:
<script type="text/javascript">
<!--
//Break out of frames
if (window != top)
top.location.href=location.href;
// -->
</script>
 
And yet... the problem targetting your form-submit to the TOP, then redirect-ing from there is: if your email-submission fails, your user will be, rather frustratingly, redirected to some unexpected location, with no notice as to whether his entry has been accepted or not.

I still prefer to notify the user (in the original frame) of the success of their transmission... THEN, if successful, use a javascript "setTimout" expression to navigate somewhere else. If the submission was NOT successful, we return to the submission page, or to an error reporting page, or somesuch.

Good luck on your project.

[red]The above is merely the opinion of Mr3Putt. He is widely regarded as a bonehead. As such, Mr3Putt accepts no responsibility for damages, real or contrived, resulting from the acceptance of his opinions as fact.[/red]
 
Okay..still having problems with this. Is there a way I can assign the redirect link to a variable? I am not sure if I have spelled out my problem very well here, but I have to pass the link in a form to a email.asp form that I have no control over. Let me know if you all have any thoughts.
 
Okay... I'll take one more crack at your problem...

This one is a javascript/iframe solution (Sorry, I'm sort of a javascript-guy).

Create a hidden IFRAME on your page, which will be the "target" for your form submission, then add some javascript variables for "redirectTo", and "initialLoad" like:
Code:
<script type="text/javascript">
var initialLoad = true;
var redirectTo = 'yourRedirectPage.asp';
</script>

<form target="iframe" action="email.asp">
  ... your form stuff here ...
</form>
<iframe style="display:none;" src="blankpage.htm" id="iframe" name="iframe" onload="if(initialLoad){initialLoad = false}else{document.location = redirectTo}">
</iframe>
Now, when you load up your form with info to send it to the "email.asp", you can set the "redirectTo" variable as needed.

What happens: When the page loads for the first time, the "initialLoad" variable is TRUE... so, when the iFrame loads, it does NOT redirect your page, instead it sets the "initialLoad" variable to FALSE... so, the next time a page loads into the iFrame, it WILL redirect you.

Remember, if you have multiple "redirect" pages, you'll need to set the "redirectTo" variable appropriately BEFORE submitting your form. I'll leave that for you to figure out.

Note: the iFrame has a "display" value of "none", which makes it invisible and keeps it from taking up space on your page.

Since you have "no control" over the "email.asp" page, you can just let it run it's merry course in your hidden iFrame, and when it's done the iFrame "onload" event will fire, and your user will be redirected.

Hopefully this advice is not completely irrelevant.
 
Thanks Mr3Putt (I can relate to you handle)for the response and explaining your logic. I will give it a shot and see if I can make it work.
 
I think I am close using Mr3Putt solution. The form is submitting to the email form in the iframe, but it is not redirecting. I can hit the back button and it goes to the correct page, but not on its own. Am I missing something?? Here is my code..

<script type="text/javascript">
var initialLoad = true;
var redirectTo = '</script>

<body>
<form target="iframe" action=" <input name="E-Mail" Type=Hidden Value="<%=rsData("EMail")%>">
<input name="Subject" Type=Hidden Value="NoZoner Data">


<Input Type=Hidden name="First Name" Value="<%=rsData("FName")%>">
<Input Type=Hidden name="Last Name" Value="<%=rsData("LName")%>">
<Input Type=Hidden name="Phone" Value="<%=rsData("Phone")%>">
<Input Type=Hidden name="Email" Value="<%=rsData("EMail")%>">
<Input Type=Hidden name="Executive Sponsor" Value="<%=rsData("ExecutiveSponsor")%>">
<Input Type=Hidden name="NoZoner Coordinator" Value="<%=rsData("Coordinator")%>">
<Input Type=Hidden name="Month" Value="<%=rsData("Month")%>">
<Input Type=Hidden name="Carpool Driver" Value="<%=rsData("CarpoolDriver")%>">
<Input Type=Hidden name="Carpool Rider" Value="<%=rsData("CarpoolRider")%>">
<Input Type=Hidden name="Miles" Value="<%=rsData("Miles")%>">
<Input Type=Hidden name="Flex Time" Value="<%=rsData("Flextime")%>">
<Input Type=Hidden name="Telecommute" Value="<%=rsData("Telecommute")%>">
<Input Type=Hidden name="Public Transportation" Value="<%=rsData("PublicTransportation")%>">
<Input Type=Hidden name="Walk to Work" Value="<%=rsData("WalktoWork")%>">
<Input Type=Hidden name="Refueled after 6 P.M." Value="<%=rsData("Refuel")%>">
<Input Type=Hidden name="Mowed Lawn After 6 P.M." Value="<%=rsData("MowLawn")%>">
<Input Type=Hidden name="Avoid The Use of Drive-Thrus" Value="<%=rsData("NoDriveThrus")%>">
<Input Type=Hidden name="Keep Thermostat at 78 Degrees" Value="<%=rsData("Thermostat")%>">
<Input Type=Hidden name="Emission Testing" Value="<%=rsData("EmissionTest")%>">
</form>
<iframe style="display:none;" src="blankpage.htm" name="iframe" onload="if(initialLoad){initialLoad = false}else{document.location = redirectTo}">
</iframe>
 
Dang.

I think that you'll need to actually create a "blankpage.htm" file. I'm pretty sure that the "onload" event does not fire when a "404-page not found" error occurs in the iFrame.

So, when your iframe loads for the first time:
Code:
<iframe style="display:none;" src="blankpage.htm" name="iframe" onload="if(initialLoad){initialLoad = false}else{document.location = redirectTo}">
</iframe>
It loads the "src" value, which is "blankpage.htm"... but if that page is not found, it just barfs. I think that, if you create the "blankpage.htm" file, then the "onload" event will occur when the page loads for the first time, thereby setting the "initialLoad" value to "false", which will cause the redirect to occur when a new page is loaded.

If it turns out that I'm <gasp> wrong about the javascript event model, I will apologize vociferously for wasting your time. But I'm pretty sure this will work... it has worked for me, anyway.

Good luck.
 
That did not work...I am using some JavaScript to auto submit the form. The user populates the entry form then clicks submit. This passes the data to a savedata page and displays the data that is being written to the database and that is being emailed (the submit is done by javascript,so the user never clicks a button). Once the data is submitted to the emailpage I want it to redirect. This is probably why the code is not working because there is no user interaction on this page to fire the event????
 
Okay, I'm not positive what the problem is, but here is a sample that works exactly as advertised... except it's quite a bit simpler than your project:
Code:
<html>
<head>
<script type="text/javascript">
var initialLoad = true;
var redirectTo = "[URL unfurl="true"]http://www.nba.com";[/URL]
function doSubmit(){
	alert('I\'m about to submit the form!');
	document.f.submit();
}
</script>
</head>
<body>
<form id="f" name="f" target="ifrm" action="[URL unfurl="true"]http://www.google.com/">[/URL]
<input type="button" value="Submit Button" onclick="doSubmit();">
</form>
<iframe id="ifrm" name="ifrm" style="width:400px;height:400px;border:3px outset #000066;" src="[URL unfurl="true"]http://www.yahoo.com/"[/URL] onload="if(initialLoad){initialLoad=false}else{document.location=redirectTo}">
</iframe>
</body>
</html>
 
I got it working thanks to Mr3Putt. I had to change the initialload = true to initialload = false and change the onload="if(initialLoad){initialLoad=false}else{document.location=redirectTo}"> to onload="if(initialLoad){initialLoad=false}else{document.parent=redirectTo}">.

Thanks for your help Mr3Putt!!!!!!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top