?

Log in

No account? Create an account
entries friends calendar profile My Website Previous Previous Next Next
Can anyone offer my friend Terry some advice? - Mark's Journal
mhaithaca
mhaithaca
Can anyone offer my friend Terry some advice?
Not sure if you write JavaScript or not, or if you know of someone I can talk to who DOES, but I'm working on a new site for Project Puffin and unfortunately for me, it is due tomorrow, and Audubon was going to write some code for me, but apparently they are having trouble doing what my boss asked for, so I wanted your advice on whether this is even POSSIBLE before I proceed any further (and possibly waste time).

I am trying to figure out how to get a web site page (see attached) to do a couple of things.

Basically, I need to write scripts to do the following two things:

1. Validate that ALL fields contain an answer BEFORE allowing user to submit form.

2. Validate ALL answers chosen, and THEN send the user to the next appropriate page (see below).

The first question we ask is just a yes or no, and we just need to record/store which they chose. That part doesn't have anything to do with how to redirect people to the next page.

BUT, the other questions are more crucial because they would decide which page people go to next, and the results should be as follows:

IF they choose PPVC AND Adopt-A-Puffin, THEN they should be redirected to:
https://loon.audubon.org/payment/donate/fulfill/PUFADT-VC.html


IF they choose PPVC AND Donation (Standard), THEN they should be redirected to:
https://loon.audubon.org/payment/donate/fulfill/PUFDON-VC.html


IF they choose PPVC AND Donation "In Honor Of", THEN they should be redirected to:
https://loon.audubon.org/payment/donate/fulfill/PUFHON-VC.html


IF they choose PPVC AND Donation "In Memoriam", THEN they should be redirected to:
https://loon.audubon.org/payment/donate/fulfill/PUFMEM-VC.html




IF they choose OTHER AND Adopt-A-Puffin, THEN they should be redirected to:
https://loon.audubon.org/payment/donate/fulfill/PUFFINADT.html

IF they choose OTHER AND Donation (Standard), THEN they should be redirected to:
https://loon.audubon.org/payment/donate/fulfill/PUFFINDON.html


IF they choose OTHER AND Donation "In Honor Of", THEN they should be redirected to:
https://loon.audubon.org/payment/donate/fulfill/PUFFINHON.html


IF they choose OTHER AND Donation "In Memoriam", THEN they should be redirected to:
https://loon.audubon.org/payment/donate/fulfill/PUFFINMEM.html



Regarding the choices when the page first loads, I purposefully did not choose any responses to be the default, because I don't want some people just clicking through without really having to choose where they heard about the project or what kind of donation they are making - I want them to HAVE to choose.

I've been wanting to learn this stuff, and have been searching the net, but I am not having much luck. I think that I just need to come up with some kind of "if.....else" coding, I've just never done it.
Am I doing things the hard way, or overlooking a simple solution?
They did not want more than one interim page, so I am trying to figure this out.

Any advice? In the meantime I will keep on searching the 'Net for possible solutions.
6 comments or Leave a comment
Comments
blaisepascal From: blaisepascal Date: November 2nd, 2008 05:27 pm (UTC) (Link)
In a recent JS/PHP project I worked on, we used jQuery and jQuery.validate to handle all of our rich JS goodies. JQuery.Validate allows you to intercept form submits and run your own validation routines in javascript before submission, which gives you some of what you want.

As for the "select which page to redirect to depending on their answers" bit... As far as I'm aware that sort of redirect selection tends to be handled server-side, not client-side. If I wanted to do it client-side, I'd probably add a hidden form element which held a value which selected which page I wanted to go to next.
From: (Anonymous) Date: November 2nd, 2008 06:05 pm (UTC) (Link)
Thanks for posting, and that sounds good...but the thing is, I've only ever written HTML. Never JavaScript. That being said...I don't really even know where to start. I bought a $40 book on the subject yesterday....but.....I'm still a bit confused as to the terms and what names of things go where. Writing HTML almost comes second nature now, but I'm not as familiar with the JavaScript language as I should be in order to pull this off.

Perhaps I should scrap this idea...?

--Terry
sskipstress From: sskipstress Date: November 2nd, 2008 06:14 pm (UTC) (Link)
jquery is where I'd look first for a tool to help you write the JavaScript you'll need. The validation part should be fairly straight-forward, though the redirection might be a bit trickier.
sskipstress From: sskipstress Date: November 2nd, 2008 06:11 pm (UTC) (Link)
We usually write our own validation routines because jquery is kinda heavy, but for someone familiar with HTML/CSS but not familiar with JavaScript, jquery is a very good suggestion.

We use server-side technology to redirect based on their answers (though sometimes what we do is server-side technology to build an appropriate page based on the answers.

If I had to use a JavaScript-only solution for determining what page to show after submitting the form, I'd use >input type="button"< or >input type="image"< for the submit button and use a JavaScript routine that looks at the values to submit the form instead of the normal method of using >input type="submit"< But I would really try for a server-side solution for this part.
retrev From: retrev Date: November 2nd, 2008 09:08 pm (UTC) (Link)
I wouldn't have js be the only method for validation/redirection as many people disable javascipt or don't have it available (mobile browsers). Relying entirely on javascript will make your site useless to these folks. Can you do the validation and redirection on the back end then add a javascript version to make it flow more smoothly? If not, at least have a static page with no validation and different links for the different pages (make the user do everything manually) then put a block of javascript that re-writes the page on load with the automatic version. That'll work for everyone.

As for the other questions, it's pretty easy to do what you want to do. When the different selections change, do the validation, etc. Have the submit button be default disabled and the form have no target link (put a dummy link in). When you validate, just edit the DOM elements for the form target and enable the submit.
From: (Anonymous) Date: November 2nd, 2008 11:02 pm (UTC) (Link)
These are all really great suggestions, but I have a feeling I am in a bit over my head with this. And I did hear about the Javascript being disabled on some sites, so that's a good point. I am going to check into some of your suggestions, though! I definitely want to learn how to write javascript. I will probably take a course, too...because it certainly can't hurt to learn more.

--Terry
6 comments or Leave a comment