Author | Topic |

Location: Launceston, Tasmania
Registered: May 2002
|
can anyone help me with some basic javascript?
|
Mon, 29 September 2003 23:49
|
 |
I'm in the middle of a javascript assignment. it is only introducary level so it is quite basic. The bit i am stuck on is this:
We have to make a webpage for a shop. The user selects the goods that they want and then proceed to the checkout. The bit i am unsure on is how to get the the details of the goods selected to show up on the following html page.
If anyone can help me with this it would be greatly appreciated. Even a link to a webpage as an example would be great
|
|
|

Location: ballarat
Registered: April 2003
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 00:29

|
 |
your problem is that you variables are not perstant to the checkout page, ie. they disappear when you go to the checkout.
i have solved this problem a few times by making my site with frames. make the parent 'frameset' html page contain the persistant variables that you want to transfer from the purchasing part to the checkout part.
so in the purchacing part you say eg. 'parent.myVariable = 30.75', load the checkout page, then use this parent variable beacuse it will still be there.
cheers
evan
|
|
|

Location: Cabramatta, NSW
Registered: May 2002
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 01:47

|
 |
You can either store the values in cookies, or you can make each link a form post (a PITA).
|
|
|

Location: ballarat
Registered: April 2003
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 03:10

|
 |
hi nark
if it is submitted via a form post, don't you need something to recive it on the server side? php, asp or cgi?
i think the assignment in question was a javascript one
good idea with the cookies though, i never thought of that
evan
|
|
|

Location: Cabramatta, NSW
Registered: May 2002
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 04:27

|
 |
No, if you submit it as a POST, then the variables are encoded into the URL, then you can use JavaScript to grab the values of the variables out.
|
|
|

Location: ballarat
Registered: April 2003
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 04:52

|
 |
um sorry to be bastard, but that aint right dude
http://forums.devshed.com/t1172/s.html
and a little test case:
js_1.html:
<html>
<body>
<form action="js_2.html" method="POST">
<input name="data" type="text">
<input type="submit">
</form>
</body>
</html>
js_2.html:
<html>
<body onload="javascript:document.write(location.hr ef);">
</body>
</html>
|
|
|

Location: Cabramatta, NSW
Registered: May 2002
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 04:54

|
 |
Oops, it was a GET then. I never remember which one is which.
|
|
|

Location: ballarat
Registered: April 2003
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 05:01

|
 |
ahh yes, i get mixed up between them too, i thought they were the other way around.
the only thing you would have to do then is parse the location text, i might use this in future web sites
cheers
|
|
|

Location: Cabramatta, NSW
Registered: May 2002
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 05:16

|
 |
From what I remember, you should just be able to refer the variables straight from JavaScript... All the parsing is done automatically...
Or am I mistaking it with PHP........ Might have to look it up....
|
|
|

Location: Perth
Registered: November 2002
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 06:44

|
 |
thats php, but for security reasons you should never do that anymore, but access through $_POST. But back to the original question, parent frames are the best way to do it in JS. I always found cookies to be a pita
|
|
|

Location: Launceston, Tasmania
Registered: May 2002
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 07:03

|
 |
Thanks guys i will have a go at the frames way tonight and see how i go. gtman, do you have any of your pages online that i could refer to?
thanks 
cam
|
|
|

Location: Perth
Registered: November 2002
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 08:40

|
 |
I don't really have any pages online that can are easily refferable. You looking for examples for said JS frame thingy?
|
|
|

Location: Baulkham Hills, Sydney
Registered: February 2003
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 09:41

|
 |
pass them through with a GET or append them to the URL yourself, and then borrow the following example 
1.html =
<html>
<body>
<a href="2.html?var1=hi&matt=cool">l ink</a>
</body>
</html>
2.html =
<html>
<head>
<script language="JavaScript">
function doSomething()
{
var args = parseQueryString();
for (var arg in args)
{
alert(arg + ': ' + args[arg]);
}
}
function parseQueryString ()
{
str = location.search;
var query = str.charAt(0) == '?' ? str.substring(1) : str;
var args = new Object();
if (query)
{
var fields = query.split('&');
for (var f = 0; f < fields.length; f++)
{
var field = fields[f].split('=');
args[unescape(field[0].replace(/\+/g, ' '))] = unescape(field[1].replace(/\+/g, ' '));
}
}
return args;
}
</script>
</head>
<body onLoad="doSomething()">
</body>
</html>
|
|
|

I supported Toymods
Location: Epping, Sydney
Registered: May 2002
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 09:44

|
 |
nerd
|
|
|

Location: Baulkham Hills, Sydney
Registered: February 2003
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 09:50

|
 |
tis true, well... i'd cop geek with just a shrug.
besides, as a result of being a geek, i can drive a 6 speed twin turbo black mark IV surpa with 19 inch rims and a kick arse sound system at age 23 
and own a house!
|
|
|

I supported Toymods
Location: Epping, Sydney
Registered: May 2002
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 09:50

|
 |
show-off nerd
|
|
|

Location: Perth
Registered: November 2002
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 10:01

|
 |
bastard 
I wouldn't use parsing a GET string, I'd do the frame thing, less code, less messy, more sanity
|
|
|

Location: Baulkham Hills, Sydney
Registered: February 2003
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 12:41

|
 |
yep, probably easier i hate frames though 
just offering options!
|
|
|

Location: Perth
Registered: November 2002
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 14:09

|
 |
Yeah, I'm not a big fan of frames either, tho iframes are much nicer, but for this application they are much more bearable then parsing huge urls. Then you would also have to generate huge href's as well to pass the information through, or make the href call a JS function to move between pages.... not my idea of fun
|
|
|

Location: Launceston, Tasmania
Registered: May 2002
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 22:39

|
 |
I wanna be a nerd like ashling what is your job dude? programmer?
|
|
|

Location: Launceston, Tasmania
Registered: May 2002
|
Re: can anyone help me with some basic javascript?
|
Tue, 30 September 2003 22:44

|
 |
thanks everyone! i ended up using ashling's (and nark's i think) method mainly because it fitted in to the page that i have already been working on. It didn't have frames to start off with so it was less muching around. Although the frames way seems to be an easier quicker way
|
|
|

Location: Cabramatta, NSW
Registered: May 2002
|
|
|

Location: ballarat
Registered: April 2003
|
Re: can anyone help me with some basic javascript?
|
Wed, 01 October 2003 00:07

|
 |
|
|
|

Location: ballarat
Registered: April 2003
|
Re: can anyone help me with some basic javascript?
|
Wed, 01 October 2003 00:09

|
 |
but i agree with ashling, i hate frames, i only use them if i have to
|
|
|

Location: Sydney
Registered: July 2002
|
Re: can anyone help me with some basic javascript?
|
Wed, 01 October 2003 06:32

|
 |
Was leaving this thread for a while as I hate javascript, but theres something I hate more - frames.
Frames are out. They've been out of the line-light for at least 3 or 4 years. Leave them alone.
Frames are evil. EVIL!
Now I'll go back to the 'quiet corner'.
|
|
|

Location: Perth
Registered: November 2002
|
Re: can anyone help me with some basic javascript?
|
Wed, 01 October 2003 06:35

|
 |
I think everyone agree's with that, but they are only used when desperately needed. The CMS I'm building will use frames for the admin section just so that stuff like navigation doesn't need to be reloaded, but don't blow your lid cause it'll be using iframes and div layers, not the normal, hell spawn framesets
|
|
|

Location: Sydney
Registered: July 2002
|
Re: can anyone help me with some basic javascript?
|
Wed, 01 October 2003 06:39

|
 |
Hell even the weblogic Console uses frames . At least 6.1 does, not sure about 8.1, we havn't gone there yet, and I couldn't be bothered playing with it, prefer games.
|
|
|

Location: Cabramatta, NSW
Registered: May 2002
|
Re: can anyone help me with some basic javascript?
|
Wed, 01 October 2003 06:41

|
 |
HKSPete wrote on Wed, 01 October 2003 16:39 | and I couldn't be bothered playing with it, prefer games.
|
Strange boy.....
|
|
|

Location: Sydney
Registered: July 2002
|
Re: can anyone help me with some basic javascript?
|
Wed, 01 October 2003 06:50

|
 |
I was a contractor for 4 years. I'm simply not used to bringing work home. 5:30 comes around I turn the computer off and leave.
|
|
|

Location: Sydney
Registered: July 2002
|
Re: can anyone help me with some basic javascript?
|
Wed, 01 October 2003 06:51

|
 |
Oh and if you were being rude
|
|
|

Location: Cabramatta, NSW
Registered: May 2002
|
Re: can anyone help me with some basic javascript?
|
Wed, 01 October 2003 06:57
|
 |
haha No, was joking...
It's Warcraft III night tonight! Can't wait to kick some arse.
|
|
|