/    Sign up×
Community /Pin to ProfileBookmark

Here’s what I want… How do I get it?

Okay. I own [url]www.fishthoughts.com.[/url] We ship fish all over the place. I need to do the following:

Have a page on my site that has a drop down box that the user can select their city from (The city list will be only cities that Delta services, and I will in put them) and then it will show them (when the ‘Get Quote’ button is pushed after city is selected) Three shipping quotes: Delta Cargo, FedEx Overnight, and FedEx Second-Day shipping. FROM THERE… I want the user to be able to select the method of shipping that they PREFER, and store this in a cookie (I think??) on their PC so that it will use that for all shipping estimates…

Might be too far out of MY league to do this… I was playing around in VB 6.0 and created a new DHTML project and came up with this:
[url]http://www.fishthoughts.com/test/shipping.htm[/url]
and it is ideally what Id like to do, but just dont know how. My site is hosted with yahoo web hosting, and has to stay that way for the next 10 months (just renewed it), and they support javascript, PHP, Perl, and MySql databases.

I would think that Id have to store all this info in a MySql DB and then reference the DB for this info, but am not too sure about the cookies, or even if thats waht I want.

I also want an online store but thats a ways away I think… I can jsut stick with my paypal store setup for now… which I still have to do.

Basically all Id like is for someone to point me in the right direction as far as what tutorials online to go take to help me out with this, or if they want to offer assistance then thats great too.

Thanks!
Steve

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@PalrosJan 22.2005 — so, you want the cookie to be saved when the form is submitted, and to be tested when the page is opened. Note the values of the input tags have to be numbers. The names all need to be the same but the values can't be, or it won't work right.

window.onload=getCookie;

function getCookie();

{

if (document.cookie && document.cookie != "" && document.cookie != undefined){

var the_cookie = document.cookie;

var my_cookie = unescape(the_cookie);

if (my_cookie.indexOf("data=") != -1){

var array = my_cookie.split("data=");

var my_data = parseInt(array[1]);

var quotes = document.my_form.prefered;

for (var i=0; i < quotes.length; i++){

if (quotes[i].value==my_data) {

qoutes[i].selected = true;

return;

}

}

}

}

}



function findPrefered()

{

if (document.cookie){

var quotes = document.my_form.prefered;

for (var i=0; i < quotes.length; i++){

if (quotes[i].selected==true) {

writeCookie(quotes[i].value);

return;

}

}

}

}



funcion writeCookie(data)

{

var the_cookie=escape(data);

var now=new Date();

var the_year=now.getFullYear()+1;

var time=new Date("December 31, "+the_year);

var expires = time.toGMTString();

the_cookie="preference="+the_cookie+";expires="+expires+";";

document.cookie=the_cookie;

}



and somewhere in the html...



<form name="my_form" onSubmit="findPrefered();">



<input type="radio" name="prefered" value="1">Delta quote

<input type="radio" name="prefered" value="2">FedEx overnight quote

<input type="radio" name="prefered" value="3">FedEx 2nd day quote
Copy linkTweet thisAlerts:
@PalrosJan 22.2005 — made a mistake. in function getCookie, i mispelled quotes. so

qoutes[i].selected=true;



needs to be



quotes[i].selected=true;



so the full code...



window.onload=getCookie;



function getCookie();

{

if (document.cookie && document.cookie != "" && document.cookie != undefined){

var the_cookie = document.cookie;

var my_cookie = unescape(the_cookie);

if (my_cookie.indexOf("data=") != -1){

var array = my_cookie.split("data=");

var my_data = parseInt(array[1]);

var quotes = document.my_form.prefered;

for (var i=0; i < quotes.length; i++){

if (quotes[i].value==my_data) {

quotes[i].selected = true;

return;

}

}

}

}

}



function findPrefered()

{

if (document.cookie){

var quotes = document.my_form.prefered;

for (var i=0; i < quotes.length; i++){

if (quotes[i].selected==true) {

writeCookie(quotes[i].value);

return;

}

}

}

}



funcion writeCookie(data)

{

var the_cookie=escape(data);

var now=new Date();

var the_year=now.getFullYear()+1;

var time=new Date("December 31, "+the_year);

var expires = time.toGMTString();

the_cookie="preference="+the_cookie+";expires="+expires+";";

document.cookie=the_cookie;

}



and somewhere in the html...



<form name="my_form" onSubmit="findPrefered();">



<input type="radio" name="prefered" value="1">Delta quote

<input type="radio" name="prefered" value="2">FedEx overnight quote

<input type="radio" name="prefered" value="3">FedEx 2nd day quote
×

Success!

Help @Fishthoughts spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...