473,883 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

select function to take users to another location

89 New Member
Hi all

I have a problem with a form script.

The form script should do the following:

When a user selects a value from a drop down list and hits the "next" button it should take him to a specific site. Also he has the option to check a checkbox "Remeber this choice" so that when he returns to the site it remembers what he has choosen from the drop down list and automatically takes him to a specific site.

Here is my code:

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript">
  2. <!--
  3. function newCookie(name,value,days) {
  4.  var days = 100;   // the number at the left reflects the number of days for the cookie to last
  5.                  // modify it according to your needs
  6.  if (days) {
  7.    var date = new Date();
  8.    date.setTime(date.getTime()+(days*24*60*60*1000));
  9.    var expires = "; expires="+date.toGMTString(); }
  10.    else var expires = "";
  11.    document.cookie = name+"="+value+expires+"; path=/"; }
  13. function readCookie(name) {
  14.    var nameSG = name + "=";
  15.    var nuller = '';
  16.   if (document.cookie.indexOf(nameSG) == -1)
  17.     return nuller;
  19.    var ca = document.cookie.split(';');
  20.   for(var i=0; i<ca.length; i++) {
  21.     var c = ca[i];
  22.     while (c.charAt(0)==' ') c = c.substring(1,c.length);
  23.   if (c.indexOf(nameSG) == 0) return c.substring(nameSG.length,c.length); }
  24.     return null; }
  26. function eraseCookie(name) {
  27.   newCookie(name,"",1); }
  29. function toMem(a) {
  30.     newCookie('theName', document.form.name.value);     // add a new cookie as shown at left for every
  31.     //newCookie('theEmail', document.form.email.value);   // field you wish to have the script remember
  32. }
  34. function delMem(a) {
  35.   eraseCookie('theName');   // make sure to add the eraseCookie function for every field
  36.   //eraseCookie('theEmail');
  38.    document.form.name.value = '';   // add a line for every field
  39.    }
  41. //-->
  42. </script>
  43. <script type="text/javascript">
  44. <!-- 
  45. function goto_URL(object) {
  46. window.location.href = object.options[object.selectedIndex].value; }
  47. //-->
  48. </script>
[HTML]<form name="form" action="http://www.printline-webshop.eu/" method="post" onSubmit="if (this.checker.c hecked) toMem(this); goto_URL(this.f orm.name)">
<select name="name" class="" id="name">
<option selected="selec ted" value="">Select one</option>
<option value="de/index.php">Germ any - German</option>
<option value="uk/index.php">Othe r - English</option>
<option value="se/index.php">Swed en - Swedish</option>
<option value="index.ph p">Denmark - Dalish</option>
<input type="submit" value="Next!" class="button" />
<input type="checkbox" id="checker" name="checker" /> <b>Remember this choice</b>
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript">
  2. <!--
  3. document.form.name.value = readCookie("theName");  // Change the names of the fields at right to match the ones in your form.
  4. //document.form.email.value = readCookie("theEmail");
  5. //-->
  6. </script>
The "Remember this choice" works partly. It remebers the choice that was made when returning to the page, but doesn't redirect when entering the site.

When hitting the "next" button it just takes the user to the action url and not the url specified in the option value of the select list.

Can anyone help me getting this script to work correctly...???

Thanks very much in advance!
Sep 30 '08 #1
2 1682
rnd me
427 Recognized Expert Contributor

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript">
  2. <!--
  3. var fo = document.form.name
  4. var val = readCookie("theName"); 
  5. if(val){ fo.selectedIndex=val; fo.form.submit(); }
  8. //-->
  9. </script>

Expand|Select|Wrap|Line Numbers
  1. function toMem(a) {
  2.     newCookie('theName', document.form.name.selectedIndex);   
  3. }
Sep 30 '08 #2
89 New Member
Hi' rnd me

I'm having some difficulties getting your fixes to work.

No matter where i put the script:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript"> 
  2. <!-- 
  3. var fo = document.form.name 
  4. var val = readCookie("theName");  
  5. if(val){ fo.selectedIndex=val; fo.form.submit(); } 
  8. //--> 
  9. </script> 
i get the error that 'document.form. name' is null or not an object.

Also it doesn't remember which value i select in the drop down menu, and it doesn't redirect the user to the specified url in the value field....

Any suggestions to what might the problem...????

Thanks in advance.
Oct 1 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

by: R.G. Vervoort | last post by:
Does anyone have a suggestion how I can order a list with names in a secondary select string. The first string selects a number of locations where people work From this string I get several id's form people (in the location table there
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
by: yb | last post by:
I have a unbound mult-select listbox field named "Locations".Multi-select option is set to "Extended". I'm having problem saving the values from this field into table. I have text column currLocations in the table in which I want to store the selected values. I do not want to go with the approach of creating another hidden textbox on the form and write code in AfterUpdate of the listbox field to populate the selected values into the...
by: ANTISPAM_garycnew_ANTISPAM | last post by:
What is the simplest way to retain the last option value selected in an html select object using javascript? I am currently using a server-side cgi language to accomplish this task, but it adds a lot of overhead and I would like to move the overhead to the remote client's PC, using javascript. Thank you for your assistance. Respectfully,
Death Slaught
by: Death Slaught | last post by:
I got bored in math today and decided to write a "program" that greets the user, and if the user has a certain name it will take them to a site, and if you're not one of the users something different happens: <html> <head> <script type="text/javascript"> var fn; var ln; var hay; var cn;
by: bdbeames | last post by:
Ok, It has been one of those days. Here is my bump in the road. I have an add user form for the administrator. The administrator enters name, password and then selects access level from a dropdown. When the data is posted I take the administrator to a page where all users can be viewed. I then allow the administrator to select a user in the list that they would like to edit. The administrator is taken back to the add user form, but the...
by: ibeehbk | last post by:
Hi. I have a form made in xhtml. I test via vbscript to make sure none of the fields are empty and properly formatted (ie email). All the regular fields work. However, I have two drop down menus that are SELECT elements (javascript-- one named arrivalcity and one named returncity). Basically they ask for a departure and return city and another menu appears with options based on that city. I can't seem to get the input from these fields in the...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.