473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

select function to take users to another location

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=/"; }
  12.  
  13. function readCookie(name) {
  14.    var nameSG = name + "=";
  15.    var nuller = '';
  16.   if (document.cookie.indexOf(nameSG) == -1)
  17.     return nuller;
  18.  
  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; }
  25.  
  26. function eraseCookie(name) {
  27.   newCookie(name,"",1); }
  28.  
  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. }
  33.  
  34. function delMem(a) {
  35.   eraseCookie('theName');   // make sure to add the eraseCookie function for every field
  36.   //eraseCookie('theEmail');
  37.  
  38.    document.form.name.value = '';   // add a line for every field
  39.    }
  40.  
  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.checked) toMem(this); goto_URL(this.form.name)">
<select name="name" class="" id="name">
<option selected="selected" value="">Select one</option>
<option value="de/index.php">Germany - German</option>
<option value="uk/index.php">Other - English</option>
<option value="se/index.php">Sweden - Swedish</option>
<option value="index.php">Denmark - Dalish</option>
</select>
<input type="submit" value="Next!" class="button" />
<input type="checkbox" id="checker" name="checker" /> <b>Remember this choice</b>
</form>[/HTML]
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 1657
rnd me
427 Expert 256MB
fixes:


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(); }
  6.  
  7.  
  8. //-->
  9. </script>

Expand|Select|Wrap|Line Numbers
  1. function toMem(a) {
  2.     newCookie('theName', document.form.name.selectedIndex);   
  3. }
  4.  
  5.  
  6.  
Sep 30 '08 #2
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(); } 
  6.  
  7.  
  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

4
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...
12
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...
11
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:
3
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...
3
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...
12
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...
2
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...

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.