Jump to content
MakeWebGames

Automatic total cost calculation in shop buy.


Will

Recommended Posts

This is just a small bit of javascript so when users buy something from the shop it works out the total cost there to save the user working it out.

Also when you click on the form it removes the default value and if they don't type anything puts it back when they remove focus.

NOTE: The money format function isn't mine it was free from some site.

Firstly put this (you must keep the ?> <? because it is not php):

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

Put it after:

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

Secondly, put:

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

After:

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

Which replaces:

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

 

It's tested and works so any problems are likly to be yours. You can see it in action on my site, Heres a screen shot:

jsshop.png

Link to comment
Share on other sites

Re: [mccode][v1]+[v2]Automatic total cost calculation in shop buy.

This is very nice. The only part I seen that you left out in the instructions for V2 is that you need to delete this part...

 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

Otherwise you will have duplicates in your shop items list.

Link to comment
Share on other sites

Re: [mccode][v1]+[v2]Automatic total cost calculation in shop buy.

Good point. I forgot that because I made it then I had to try and remember what it was before to post on here.

I have edited the first post because it applies to both versions.

Link to comment
Share on other sites

  • 3 months later...
  • 2 months later...

Re: [mccode][v1]+[v2]Automatic total cost calculation in shop buy.

Maybe I'll post me AJAX for viewuser :-D; though it shouldn't be too difficult for someone who knows what they are doing to take.

The only problem with JavaScript is that some people don't have it turned on; so any JavaScript has to be done without as well. However is it acceptable to not bother and just use JavaScript for some things?

Link to comment
Share on other sites

Re: [mccode][v1]+[v2]Automatic total cost calculation in shop buy.

Not really, a web developer should always take into account the fact that some people do not have javascript enabled.

But the average gamer has javascript enabled, and doesn't know of better.

I'm not saying to take advantage of that, but it does help with game developing, I have seen a fair share of games that uses javascript for just about everything, and they are doing quite well in doing so.

So my verdict on this would be, for games, sure go ahead, equip your game with ajax, and join the realm of web 2.0 websites.

Link to comment
Share on other sites

  • 1 month later...

Re: [mccode][v1]+[v2]Automatic total cost calculation in shop buy.

Hi. Ive had this trouble with a few scripts and this one included. Im getting a $end error even when using fully working code people use. Is there a php module that I need to have enabled. This is the only thing I can think of. Before I mess around does anyone have any idea. Many thx in advance for any help anyone can give.

Link to comment
Share on other sites

Re: [mccode][v1]+[v2]Automatic total cost calculation in shop buy.

 

Hi. Ive had this trouble with a few scripts and this one included. Im getting a $end error even when using fully working code people use. Is there a php module that I need to have enabled. This is the only thing I can think of. Before I mess around does anyone have any idea. Many thx in advance for any help anyone can give.

As for your situation, i would suggest downloading notepad++ opening the file as a .php file then go through all { and wich ever one does not go red, there's your situation.

Link to comment
Share on other sites

  • 8 years later...
Ok, js, or ajax, or whatever, is far not my strong suit. So, I've used this in replacement to fit mine (js not changed any)

 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

Button displays the price, but does not update to the new price after input.

 

Why not do something like this: https://jsfiddle.net/zf7rbqaL/

 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

(Put the oninput stuff in a function for easier readability, this was a quick hack to show you.)

Link to comment
Share on other sites

That changed the layout a bit, but still the same as the previous. The automatic total will not adjust within the submit button for purchase. But since I'm wanting to turn this into more of a shopping cart, allowing more than 1 item purchase at a time, I don't think I'mma worry about this mod for now, anyways.

But ty!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...