Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 6th, 2005, 05:10 PM
Registered User
 
Join Date: Mar 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Project Assistance

Hello,

I have a project that I would Greatly Appreciate some direction.

My goal is to create a "Sales Assistant Script" that recommends products based upon Response's to questions.

I know enough JavaScript to successfully create a "JavaScript Error" 2 out of 3 times! <Grin>

The books I have read are great in regards to understanding what the code is doing, but in my novice opinion don't teach me the "when to use what" examples. Maybe that comes with experience.

In any event I really need some help as to how to get started in this task? I'd like to know what do you Seasoned Script Writers do to begin to create/write this type of script? Do you have a list of favorite functions, methods etc and you use and reuse? Or do you do like me and hunt for what script to use and hope it works.

What do I need to do ?

Thanks,
Richard
txknapper at hotmail.com

 
Old April 6th, 2005, 09:18 PM
Authorized User
 
Join Date: Apr 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

start with www.w3schools.com
a great beginner tutorial and free...
:D
then find your favorite search engine and click away (preserve copywrites... people like that :D)

In a world of give and take, take all you can and you die with nothing. Give all you can and you die with honor.
 
Old April 7th, 2005, 04:19 AM
Registered User
 
Join Date: Mar 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for that information. I have already done the w3schools tutor and passed their quiz.

I'm looking for a little more concrete type of information.

Some simple script that will allow me to build my Sales Associate that recommends products based upon user input.

Here is what I am thinking so far.

I'm "guessing" that I will need to have a set of lets say 12 questions. I will group these questions in groups of 4. If the User selects a combination of questions, then my script will recommend the user purchase certain products.

So what I need to know is how do you assign or group the selection of buttons or check marks, to specific product recommendations?

I'm looking for the Simplist way of getting this done.

Thank you VERY Much for any assistance!

Thanks again,
Rich

 
Old April 7th, 2005, 09:04 PM
Authorized User
 
Join Date: Apr 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Plan out your page
4 sections...my example would be for purchasing a car...

1. the html page that shows the form (ei:the 12 questions)
2. validation script (is the form filled out correctly?)
3. "crunching" script (take the data provided and produce an answer)
4. display results (usually a new webpage, but can be on the same page)

Page1 (home_page.htm)
<html><head><title>Sales Associate</title>
<script ="javascript" src="validation.js"></script>
<body>
<form name = "yourchoices" method="post">
What color do you want?
<input name="choice1" value="Blue" type="radio"><br>
<input name="choice1" value="Red" type="radio"><br>
<input name="choice1" value="Black" type="radio"><br>
<input name="choice1" value="Green" type="radio"><br>
<br>
What average MPG are you looking for?
<input name="choice2" value="0-10" type="radio"><br>
<input name="choice2" value="11-20" type="radio"><br>
<input name="choice2" value="21-40" type="radio"><br>
<input name="choice2" value="41+" type="radio"><br>
<br>
What type or style car are you looking for?
<input name="choice3" value="Sedan" type="radio"><br>
<input name="choice3" value="SUV" type="radio"><br>
<input name="choice3" value="Compact" type="radio"><br>
<input name="choice3" value="Anything that runs" type="radio"><br>
<br>
<input value="Submit" onclick="valadate();" type="button">
</body></html>


Page2 (valadation.js) (ok so I mixed steps 2 and 3 together here...)
function valadate()

{
var a= document.yourchoices.choice1; var option1= -1
var b= document.yourchoices.choice2; var option2= -1
var c= document.yourchoices.choice3; var option3= -1

for (i=0;i<a.length;i++)
    {if(a[i].checked)
    {option1=a[i].value}}
if (option1 == -1) {
alert("You must select a radio button from the first set of options");
return false;}

for (j=0;j<b.length;j++)
    {if(b[j].checked)
    {option2=b[j].value}}
if (option2 == -1) {
alert("You must select a radio button from the second set of options");
return false;}

for (k=0;k<c.length;k++)
    {if(c[k].checked)
    {option3=c[k].value}}
if (option3 == -1) {
alert("You must select a radio button from the third set of options");
return false;}


4. Here is where I myself have problems... this is where a person would normal write :
if (option1="red" && option2="21-40" && option3="compact")
    alert ("You need a 4-cylinder Ford Escort")
and then continue with every possible combination... (about 41? i think)
if there is an easier way... i would like to know as well :D

Hope to help...

In a world of give and take, take all you can and you die with nothing. Give all you can and you die with honor.
 
Old April 7th, 2005, 09:14 PM
Authorized User
 
Join Date: Apr 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

in the htm page I forgot to actually let the user SEE what they're selecting... oops....
in the statement(s)
<input name="choice1" value="Blue" type="radio"><br>
you need to add what is written in the value "" section to the end before <br>

<input name="choice1" value="Blue" type="radio"> Blue <br>

sorry 'bout dat.

In a world of give and take, take all you can and you die with nothing. Give all you can and you die with honor.
 
Old April 7th, 2005, 10:58 PM
Registered User
 
Join Date: Mar 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Hatchingabrain
 in the htm page I forgot to actually let the user SEE what they're selecting... oops....
in the statement(s)
<input name="choice1" value="Blue" type="radio"><br>
you need to add what is written in the value "" section to the end before <br>
Wow! That is quite the example!! Thank you very much for making this clearer for me. I will look at what you have posted and digest all of that info.

How long does it take to get where you can put script together like putting together a sentence? In other words right now I try a little script, Read, debug, and Search for References and or clearer explanations. And then I try more script until I get what I am looking for.

I can't wait until I can write script as fast as writing an email.

Or is that unrealistic?

Thank you very much.
Rich






Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Assistance KramRJ C++ Programming 2 May 19th, 2007 07:24 AM
I need u guys assistance acube4real C++ Programming 1 October 20th, 2006 08:27 AM
Assistance with function mat41 Classic ASP Professional 3 August 11th, 2006 12:01 PM
XSLT Assistance MarkHA XSLT 0 November 7th, 2005 12:08 AM
Network Assistance DuncanFinney C# 6 August 1st, 2005 06:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.