• Home
  • Q&A
  • Javascript Code Won't Work On My Blogger Site
 
4
0
0

Javascript Code Won't Work On My Blogger Site

Dunya CengizviaStackOverflow
October 03, 2012
0 score
1 answers

I have made a javascript code using fiddle.com website. But in fiddle i can only make it work by using

no wrap (body)

option. Im not sure what does this option do. The link for the Fiddle is here. I added this script to my blogger blog, but it would not work.

The script is to calculate a total price of the selections. You can see it in fiddle also i have it on blogger but as i said it's not working. :/

The link to my blog is here.

I'll be so happy if someone can help me out with this. Thanks.

Answers

2 score

no wrap (body) means that your script will be inserted in new script tag inside body tag, no wrap (head) means that your script will be inserted in new script tag inside head. You can read about it on jsFiddle help

Other options will wrap your JS code inside particular DOM event handlers (onLoad and onDomReady)

Script errors on your site tells me that calculateTotal is not defined, so please check your naming.

Why do you use string when calculating total? You can safely use native JS parseInt funciton.

Another point that using form click event is wrong, you should use change event of your inputs.

Simplest option for you is to use jQuery like this:

$('[name="CPU"], [name="OperatingSystem"], [name="Case"]').on('change', updateTotal);

function updateTotal {
   var total = 0;
   // calculate your total here
   $('#totalspan').text(total);
}

Please check my 5-min fiddle: http://jsfiddle.net/GDXuS/5/

You could also use data- attributes to store price or any other data (see on jQuery site).

And I'm advice you to study some programming languages.

answered October 03, 2012
Discussion

-