Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


redirection to an another webpage



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> JavaScript Forum
View previous topic :: View next topic  
Author Message
paul555



Joined: 14 Jun 2008
Posts: 6

PostPosted: Sat Jun 14, 2008 9:39 am    Post subject: redirection to an another webpage Reply with quote

Hi all .I start learning html and javascript a little way back and now i wonder how to implement the situation described here.I have an index.html with a form like this
Code:
<form action="" method="post">
      <p>
         <label>name</label>

         <input name="dname" value="Your name" type="text" size="30" />         

         <br /><br />

         <input type="submit" value="Submit" onclick="displaypage()/>
      </p>      

         </form>   

Now i want if the name entered in the input is "paul" and the user click the submit button the browser to go and display in the same window the paul.html page else if the name entered in the input is "jim" and the user click the submit button the browser to go and display in the same window the jim.html page.I suppose i have to make something like this in the head section of index.html page
Code:
<script type="text/javascript">
function displaypage()
{
   switch(n)
   {
      case 1:
           paul.html
           break;   
      case 2:
           jim.html
           break;
      default:
           alert("Wrong Name");
}

}

</script>

Any suggestions how the above may work?
Back to top
View user's profile Send private message
rangana
500+ Club


Joined: 27 Feb 2008
Posts: 718
Location: Cebu City Philippines

PostPosted: Sat Jun 14, 2008 10:19 am    Post subject: Re: redirection to an another webpage Reply with quote

Here's a working example which on the light side, take in consideration other names, any name that is inside the dname textbox:
Code:
]
<script type="text/javascript">
function displaypage()
{
   var ext='htm'; // Extension of your page. You cou
   location.href=document.getElementsByName('dname')[0].value+'.'+ext;
}

</script>

<form action="" method="post">
<p><label>name</label>
<input name="dname" value="Your name" type="text" size="30" />         
<br /><br />
<input type="button" value="Submit" onclick="displaypage()"/>
</p>
</form> 


If you only want to accept exclusive values (Jim and Paul) do some restrictions. Just get back if you're still stumped.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
paul555



Joined: 14 Jun 2008
Posts: 6

PostPosted: Sat Jun 14, 2008 11:34 am    Post subject: Re: redirection to an another webpage Reply with quote

Thanks for your answer.I tried your example like that
Code:
<script type="text/javascript">
function displaypage()
{
  var ext='html';
  location.href=document.getElementsByName('dname').value+'.'+ext;
}
</scrit>
but it didn't work.Also i think and i tried that
Code:
<script type="text/javascript">
function displaypage(dname)
{

   if(dname="paul"){
      location.href=p/paul.html;
      }
</script>

with
Code:
<form action="" method="post">
<p><label>name</label>
<input name="dname" value="Your name" type="text" size="30" />         
<br /><br />
<input type="button" value="Submit" onclick="displaypage()"/>
</p>
</form>
and also didn't work.Now i am confused.What can i do?
Back to top
View user's profile Send private message
rangana
500+ Club


Joined: 27 Feb 2008
Posts: 718
Location: Cebu City Philippines

PostPosted: Sat Jun 14, 2008 11:57 am    Post subject: Re: redirection to an another webpage Reply with quote

Because you're changing my script erroneously.
Code:

<script type="text/javascript">
function displaypage()
{
  var ext='html';
  location.href=document.getElementsByName('dname')[0].value+'.'+ext;
}
</script>
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
paul555



Joined: 14 Jun 2008
Posts: 6

PostPosted: Sat Jun 14, 2008 12:20 pm    Post subject: Re: redirection to an another webpage Reply with quote

Sorry i didn't noticed that i did that error.I tried that
Code:

<script type="text/javascript">
function displaypage()
{
  var ext='html';
  location.href=document.getElementsByName('dname')[0].value+'.'+ext;
}

and also that
Code:

<script type="text/javascript">
function displaypage()
{
   var p = "paul";

   if(dname=p){
      var ext='html';
        location.href=document.getElementsByName('dname')[0].value+'.'+ext;
        }
   else
      alert("Wrong name");
}
</script>
   
but still no luck
Back to top
View user's profile Send private message
rangana
500+ Club


Joined: 27 Feb 2008
Posts: 718
Location: Cebu City Philippines

PostPosted: Sat Jun 14, 2008 12:31 pm    Post subject: Re: redirection to an another webpage Reply with quote

This part is wrong:
Code:

if(dname=p)


You haven't declared dname and comparison should be double equal sign (==) Sad

Hopefully, this tweak should work:
Code:

<script type="text/javascript">
function displaypage()
{
   var p = "paul",
   dname=document.getElementsByName('dname')[0].value;
   if(dname==p){
      var ext='html';
        location.href=dname+'.'+ext;
        }
   else
      alert("Wrong name");
}
</script>
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
paul555



Joined: 14 Jun 2008
Posts: 6

PostPosted: Sat Jun 14, 2008 1:25 pm    Post subject: Re: redirection to an another webpage Reply with quote

Thanks for your reply.Now if i type a different name than paul it shows the alert box but if i type paul it just refresh index.html.If i understand correctly the paul.html file should be in the same folder as index.html?(i have them in the same folder)
Back to top
View user's profile Send private message
rangana
500+ Club


Joined: 27 Feb 2008
Posts: 718
Location: Cebu City Philippines

PostPosted: Sat Jun 14, 2008 1:45 pm    Post subject: Re: redirection to an another webpage Reply with quote

It works!
You're seeing the forms behavior when pressing the "Enter" button. If you hate its reaction when pressing enter, then remove your form, since you haven't used it (yet).
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
paul555



Joined: 14 Jun 2008
Posts: 6

PostPosted: Sat Jun 14, 2008 2:03 pm    Post subject: Re: redirection to an another webpage Reply with quote

But i want the change happen through an input text box.So that isn't possible?
Back to top
View user's profile Send private message
paul555



Joined: 14 Jun 2008
Posts: 6

PostPosted: Sat Jun 14, 2008 2:30 pm    Post subject: Re: redirection to an another webpage Reply with quote

I am sorry.My mistake Embarassed I removed theese two lines
Code:
<form action="" method="post" onSubmit="return displaypage()">

Code:
</form>

And all are working ok.Thanks very much for your help.
Back to top
View user's profile Send private message
rangana
500+ Club


Joined: 27 Feb 2008
Posts: 718
Location: Cebu City Philippines

PostPosted: Sun Jun 15, 2008 7:31 am    Post subject: Re: redirection to an another webpage Reply with quote

No problem. You're completely welcome. Wink
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> JavaScript Forum All times are GMT + 1 Hour
Page 1 of 1

 
 
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User: Pass:
Log me on automatically each visit:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap