Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-15-2012, 01:52 PM   PM User | #1
sblatch
New to the CF scene

 
Join Date: Dec 2011
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
sblatch is an unknown quantity at this point
Using JS to redirect form select (no submit)

I want to have a selection of form elements:

Code:
<form action="" method="post" enctype="multipart/form-data" name="mps_service" target="_top" dir="ltr" lang="en">
 <select name="service" id="service">
    <option value="buy">Buy a Home</option>
    <option value="rent">Rent a Home</option>
    <option value="sell">Sell a property</option>
  </select>
</form>
Which then redirect to a relevant page once clicked. I do not want a submit button or to use a css menu as I want to be in the default form browser style to match other elements.

I have tried using the following in the <head>

Code:
<script type="text/javascript" language="javascript">
   function redirectbuy()
    {
        document.location.href="http://www.buy-site.com"
    }
function redirectrent()
    {
        document.location.href="http://www.rent-site.com"
    }
   function redirectsell()
    {
        document.location.href="http://www.sell-site.com"
    }
</script>
and then changing the form code to:

Code:
<form action="" method="post" enctype="multipart/form-data" name="mps_service" target="_top" dir="ltr" lang="en">
 <select name="service" id="service">
    <option type onselect="redirectbuy()">Buy a Home</option>
    <option type onselect="redirectrent()">Rent a Home</option>
    <option type onselect="redirectsell()">Sell a property</option>
  </select>
</form>
I am a total newbie and any guidance would really be appreciated.
sblatch is offline   Reply With Quote
Old 11-15-2012, 06:15 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,383
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript">
function travel()
{
	var locationObj = document.location;
	if(document.getElementById("service").value == "buy") document.location = 'http://www.mozilla.org';
	if(document.getElementById("service").value == "rent") document.location = 'http://www.yahoo.org';
	if(document.getElementById("service").value == "sell") document.location = 'http://www.google.org';
}
</script>
</head>

<body>
Your Choice Buy, Rent, or Sell<br />
<select name="service" id="service" onchange="travel()">
	<option></option>
	<option value="buy">Buy a Home</option>
	<option value="rent">Rent a Home</option>
	<option value="sell">Sell a property</option>
</select>
</body>
</html>
sunfighter is offline   Reply With Quote
Users who have thanked sunfighter for this post:
sblatch (11-20-2012)
Old 11-20-2012, 07:23 AM   PM User | #3
sblatch
New to the CF scene

 
Join Date: Dec 2011
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
sblatch is an unknown quantity at this point
Thanks Sunfighter!

Simple and perfect!

:-)
sblatch is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript, onselect

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:41 AM.


Advertisement
Log in to turn off these ads.