Form Redirect to open specified page

V

Von Aras

Hi all,

I have a small classifieds site and I use the following script to open the
specific ads in a FRAME - "Enter Ad Number".

I have since done away with the frames and the script now has problems.

What I want to do is change it so that it will open in the current window -
and not a FRAME.

Is there a quick fix for this?



<script language="JavaScript">

function AdJump()
{
var vPage;
vPage = document.adjump.adnum.value;
vPage = http://www.anypage.com/photoads/ads + vPage + ".html";
document.open();
document.location.href = vPage;
document.close();

}

</script>


<CENTER>
<FORM NAME="adjump" OnSubmit="AdJump()">
<TABLE WIDTH=100% CELLPADDING=0 CELLSPACING=0>
<TR><TD WIDTH=10%> &nbsp; </TD>
<TD WIDTH=90% align="center">
<INPUT TYPE="Text" SIZE=3 VALUE="" NAME="adnum"><BR>
Enter Ad Number</FONT>
</TD></TR>
<TR><TD WIDTH=10%> &nbsp; </TD>
<TD WIDTH=90% align="center">
<INPUT TYPE="Submit" VALUE="Submit">
<INPUT TYPE="Reset" VALUE="Reset">
</TD></TR>
</TABLE>
</FORM>
</CENTER>
 
M

McKirahan

--
--D. McKirahan
(e-mail address removed)


Von Aras said:
Hi all,

I have a small classifieds site and I use the following script to open the
specific ads in a FRAME - "Enter Ad Number".

I have since done away with the frames and the script now has problems.

What I want to do is change it so that it will open in the current window -
and not a FRAME.

Is there a quick fix for this?



<script language="JavaScript">

function AdJump()
{
var vPage;
vPage = document.adjump.adnum.value;
vPage = http://www.anypage.com/photoads/ads + vPage + ".html";
document.open();
document.location.href = vPage;
document.close();

}

</script>


<CENTER>
<FORM NAME="adjump" OnSubmit="AdJump()">
<TABLE WIDTH=100% CELLPADDING=0 CELLSPACING=0>
<TR><TD WIDTH=10%> &nbsp; </TD>
<TD WIDTH=90% align="center">
<INPUT TYPE="Text" SIZE=3 VALUE="" NAME="adnum"><BR>
Enter Ad Number</FONT>
</TD></TR>
<TR><TD WIDTH=10%> &nbsp; </TD>
<TD WIDTH=90% align="center">
<INPUT TYPE="Submit" VALUE="Submit">
<INPUT TYPE="Reset" VALUE="Reset">
</TD></TR>
</TABLE>
</FORM>
</CENTER>

What does "... now has problems" mean?

What you have works for me but I'd change it slightly; watch for word-wrap.

<script type="text/javascript">
function AdJump()
{
var aPage = "http://www.anypage.com/photoads/ads";
var vPage = document.adjump.adnum.value;
location.href = aPage + vPage + ".html";
}
</script>
 
V

Von Aras

What does "... now has problems" mean?
What you have works for me but I'd change it slightly; watch for


<script type="text/javascript">
function AdJump()

var aPage = "http://www.anypage.com/photoads/ads";
var vPage = document.adjump.adnum.value;
location.href = aPage + vPage + ".html";

</script>



Thanks Mckirahan,

Because my script was designed for a FRAME - it opens the new page AND THEN
changes to the selected page - leaving an annoying blank page in between the
old and the new page (when not used in a frame).

I can't get it to do anything exactly the way you wrote the changes - but I
will keep playing around with it.

Thanks for the suggestion and the quick answer.

-Von
 
V

Von Aras

I actually found a simpler way to do it:


<script type="text/javascript">
function AdJump()
{
window.location.href = http://www.anysite.com/ads/ +
document.getElementById("adnum").value + ".html";

}
</script>

</head>

<body>

<p><input id="adnum" type="text" value size="04"><br>
<button onclick="AdJump()">Enter Ad Number</button><br>
</p>

</body>


Thanks :)
 
V

Von Aras

Hmmm.

I just noticed that the submit button doesn't highlight with 'button
onclick' - and you have to manually click the Submit button instead of just
hitting ENTER.

Please disregard my premature jumping-for-joy!

Anyone have any ideas?

Here is the script again:


<script type="text/javascript">
function AdJump()
{
window.location.href = http://www.anysite.com/ads/ +
document.getElementById("adnum").value + ".html";

}
</script>
</head>

<body>

<p>
<input id="adnum" type="text" value size="04"><br>
<button onclick="AdJump()">Enter Ad Number</button><br>
</p>

</body>
 
M

McKirahan

Von Aras said:
Hmmm.

I just noticed that the submit button doesn't highlight with 'button
onclick' - and you have to manually click the Submit button instead of just
hitting ENTER.

Please disregard my premature jumping-for-joy!

Anyone have any ideas?

Here is the script again:


<script type="text/javascript">
function AdJump()
{
window.location.href = http://www.anysite.com/ads/ +
document.getElementById("adnum").value + ".html";

}
</script>
</head>

<body>

<p>
<input id="adnum" type="text" value size="04"><br>
<button onclick="AdJump()">Enter Ad Number</button><br>
</p>

</body>

Perhaps this variation is what you want?:

<html>
<head>
<script type="text/javascript">
function AdJump() {
var form = document.forms[0];
if (form.adnum.value == "") return false;
form.action = form.action.replace(/#/,form.adnum.value);
return true;
}
</script>
</head>
<body>
<p>
<form action="http://www.anysite.com/ads/#.html"
method="post" onsubmit="return AdJump()">
Enter Ad Number:
<input id="adnum" type="text" value size="4" maxlength="4">
<input type="submit" value="Submit">
</form>
</p>
</body>
</html>
 
V

Von Aras

Your code brings back a correct URL - but it doesn't actually work.

I get a 'HTTP 405' error - 'Resource not allowed'.

But if I click the "Go" button again - it works - with the same URL that was
previously generated.

Very strange. :(
 
M

McKirahan

Von Aras said:
Your code brings back a correct URL - but it doesn't actually work.

I get a 'HTTP 405' error - 'Resource not allowed'.

But if I click the "Go" button again - it works - with the same URL that was
previously generated.

Very strange. :(


Try this
<input name="adnum" type="text" size="4" maxlength="4">

instead of
<input id="adnum" type="text" value size="4" maxlength="4">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top