Jump to content

Fast Calc


Illasera

Recommended Posts

A common question : I have a shopping cart, And i have :X - products,Y - The amount of money per product,Z - How many products i wish to buy.I wish to calculate the Product cost (Y) multiply (*) by the amount of products (Z). aka Y * Z.and i wish for it to be On client side(Javascript) and with no refresh(jquery). aka Client Runtime.Any points on how? am not exprienced in javascript,So a few indicators on "How to" Will be great :)Thanks in advance.

Link to comment
Share on other sites

Do you know any programming at all?If you have the list of products and their prices and how many there are, you just need to do the multiplication and sums.
As you may or may not noticed, am looking for the short way, a pointer for where i can get a working example of it, I have no knowledge of javascript and can`t be bothered to learn it right now.In general i am vs Feeding someone right up(And giving away the answer) without trying first, But i need to make an exception this time.I should mention that am quite aware of the fact that i won`t reach far without learning js and i am intending to learn it, But not for this current example.
Link to comment
Share on other sites

As you may or may not noticed, am looking for the short way, a pointer for where i can get a working example of it, I have no knowledge of javascript and can`t be bothered to learn it right now.In general i am vs Feeding someone right up(And giving away the answer) without trying first, But i need to make an exception this time.I should mention that am quite aware of the fact that i won`t reach far without learning js and i am intending to learn it, But not for this current example.
sorry to say, that's probably not going to yield much help from anyone around here. No one will do it for you, and what you're proposing is beginner in nature. You would probably be able to get the solution in a short amount of time (with assistance from the community) if you came across as a little more eager and willing to at least invest in some basic elementary level of effort.
Link to comment
Share on other sites

sorry to say, that's probably not going to yield much help from anyone around here.
Yea i figured that much, I wouldn`t help someone else who posted the same thing as well, But no harm in trying, I have a deadline to take into an account,And to study even the basic of JS in such a short notice, Will be hard.The plan was to ask for a ready up code and study it later, But i guess ill figure in some way how to make it, Thanks anyway :)
Link to comment
Share on other sites

I mean the basics are easy, you just have to try. I assume you just need a form to enter values and display the results, and a function that will take the values and calculate the output. There's a tutorial on forms at W3schools, and that's just basic markup. The function would run then the submit button is clicked, and would just use docuement.getElementById to get the values of the form's, and then like Ingolme said, the rest is just basic math.

Link to comment
Share on other sites

I mean the basics are easy, you just have to try. I assume you just need a form to enter values and display the results, and a function that will take the values and calculate the output. There's a tutorial on forms at W3schools, and that's just basic markup. The function would run then the submit button is clicked, and would just use docuement.getElementById to get the values of the form's, and then like Ingolme said, the rest is just basic math.
Nice, Thank you, Good pointers there, Do i also need to use Jquery if i wish to prevent refrashes on update? or there are some events like onchange, and stuff that can do the job?Guess i just need to try :)
Link to comment
Share on other sites

jQuery is written with JavaScript. jQuery is not a separate language, but simply a library used to make common tasks in JavaScript easier.That said, anything you do in JavaScript will not refresh the page (unless you explicitly tell it to) so yeah, you'd use onchange, onblur, or onclick events to do your calculations.

Link to comment
Share on other sites

jQuery is written with JavaScript. jQuery is not a separate language, but simply a library used to make common tasks in JavaScript easier.
Yea i know its an extension lib, but since it uses slightly different syntax and commands, i treat it as something different.
That said, anything you do in JavaScript will not refresh the page (unless you explicitly tell it to) so yeah, you'd use onchange, onblur, or onclick events to do your calculations.
Thanks, Ill give it a go :)
Link to comment
Share on other sites

How do i print a value from javascript into a paragraph? I have seen many people post it values inside forms, But i wish to return the values within a paragraph.Also, How do i overwrite certain object behaviour, Say i want all of my input boxes to inherit the default behaviour , yet some events i want to change,But am not talking about calling a different function on each event, but to actually overwrite the event default behaviour?Thanks in advance.

Link to comment
Share on other sites

well, one thing at a time. In order to write to a paragraph as you asked, make the paragraph has an id associated with it. Then, you would just a combination of document.getElementById and innerHTML, i.e.

document.getElementById("elements_id").innerHTML = "your text here";

I'm not really sure what you're getting at with the rest of your post. Do you have a specific example in mind?

Link to comment
Share on other sites

A common question : I have a shopping cart, And i have :X - products,Y - The amount of money per product,Z - How many products i wish to buy.I wish to calculate the Product cost (Y) multiply (*) by the amount of products (Z). aka Y * Z.
This sounds like a homework problem to me.
Link to comment
Share on other sites

well, one thing at a time. In order to write to a paragraph as you asked, make the paragraph has an id associated with it. Then, you would just a combination of document.getElementById and innerHTML, i.e.
document.getElementById("elements_id").innerHTML = "your text here";

I'm not really sure what you're getting at with the rest of your post. Do you have a specific example in mind?

I can only give you an example from the C++ programming language, where its called "Overloaded operator/function,You take an object, And you inherit its default behaviour, Yet you can change some of the object aspects, (This is called OOP - Object-oriented programming).Here is my example,Say i have an input text box.And when the user gets focus on it, It`s changes the input text box areacolor to black.Now there should be 2 ways to achieve that goal.1.)onchange event trigger some function.2.)overwriting the onchange default behaviour (Making a new object from an old object in simplicity) to do my own special function. (Can i do that, Since javascript should be OOP, i dont see why not)?Now my question is, If i can overwrite objects, How do i do that(What`s the correct syntax in javascript for doing it, The toturials lack that info).Thanks guys.
This sounds like a homework problem to me.
Am way over my student years mate :)And believe me mate, What i am trying to do is way more complex than what i have written in my original post, I was just trying to simplfy it to get the basics.
Link to comment
Share on other sites

AFAIK, I'm not sure if there are any default behaviors for event handlers, the idea behind them is that you define their actions through the use of functions.

Link to comment
Share on other sites

With most events that happen, about all you can do is handle the event, cancel the default actions, and then do whatever you want. You're not overriding an object or anything, you just define an event handler, which gets sent an event object describing the event, and you can use the event object to cancel the default actions or stop the event from propagating to other elements. If you want to override that event object, I suppose you could add your own properties or methods to the prototype, but you can't override an event object before the event happens. The event object gets created once the event happens and gets passed to the event handler. There's not a specific event object for onchange, once the change event happens an event object gets created and loaded with properties that say it's a change event, which element the event applies to, any keys that were pressed, etc. This has a good summary:http://www.quirksmode.org/js/introevents.htmlhttp://www.quirksmode.org/dom/events/index.html

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...