Forum Moderators: open

Message Too Old, No Replies

Javascript swaps

does it have to be in the <head>?

         

too much information

3:52 pm on Aug 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a javascript that swaps the values of an order form based on a user's selections. It's very basic, but does the javascript actually need to be in the <head> section of the page or can I put it anywhere?

Also, I would like to be able to generate an encoded version of the script using PHP. I have used iScramble for this but I'm not sure if creating an encoded javascript of a javascript will work. Do you think it will work if I just encode the functions?

garann

8:06 pm on Aug 5, 2005 (gmt 0)

10+ Year Member



I think a Javascript function needs to be in the <head> for certain browsers. Script you want to have run inline can be anywhere on the page.

I'm not 100% sure what you mean about encoding your Javascript - hopefully someone with more insight will answer - but I think that if you try to present an encrypted or scrambled version of your script, it's not going to work.

bruhaha

8:28 pm on Aug 5, 2005 (gmt 0)

10+ Year Member



does the javascript actually need to be in the <head> section of the page or can I put it anywhere?

Are you looking to put it somewhere else on the page, or in an external file (which you would then link to in the <head> )? The latter should work. The former depends on the particular code --many simple methods can be used anywhere, others have to be called in the head because they need to be applied FIRST, before other code. (Can you test it in the head, then just try moving it into the body and see if it still works?)

kaled

11:36 pm on Aug 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Javascript can be placed anywhere in a page where html tags are allowed.

I often use scripts at the bottom of pages.

Kaled.

too much information

3:01 pm on Aug 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The encoded script looks like a bunch of random letters but produces the same results on the screen. I'm just trying to hide my form variables so that people can't manually adjust prices using a javascript of their own.

I've been having trouble encoding javascripts that are in the <head> section of the page, but it works great in the <body> portion. I was just unsure if I could move my javascripts from the <head> to the <body> and have them still work.

Actually the external file would be a great idea, except that the values in the javascript are created dynamically using PHP.

john_k

3:09 pm on Aug 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm just trying to hide my form variables so that people can't manually adjust prices using a javascript of their own.

You should never rely on pricing information sent from the browser. Someone that wants to spoof your cart wouldn't need your javascript at all. They would just need to create their own simple form (with absolutely no javascript) and set it to POST to the same target file. This would probably be much easier than trying to manipulate the javascript.

ANY of the information coming from the browser can be spoofed.

Let the browser tell you the quantities. But the server should determine the price.