I need to read the span value and insert into database in php
<span class="GrandTotal">0.00</span>

Recommended Answers

All 14 Replies

Do you want to do this via ajax/javascript or via a traditional form posting?

I aksed you an either or question.

Eg do you want tea of coffee?

You answered yes - do you see how that causes me a problem?

Oh sorry. I can do with ajax/javascript.

Ok and is the span content being changed somehow after the page is loaded?

yes. It's have a dynamic value which is changed when the amount is changed.

Ok then you use some javascript to read its value and make an ajax call to update it on the server.

If this is the only item on the page with a class of GrandTotal I would possibly give it id="GrandTotal" instead.

You can then access that via script and send it to a server side method to insert it into the database via ajax. Do you do any other ajax in your app?

i do. I used ajax for fetcing the data from the database

Another thought about security - you realise that a user can easily change the value themselves - this isn't a real ecommerce site or anything like that is it?

How can you use ajax? Depends - have you used it elswhere on your site yet?

Ok so lets break this down one thing at a time. Firstly how/when do you want this code to be invoked? Also what style of Ajax are you using - hand written with jquery, some kind of other library maybe?

Member Avatar for diafol

Good point about security DA. Even normal forms can be spoofed and depending on the use case, the arithmetic should be done on the server, not taken from a form. Using JS to give the user feedback is fine though. All input must be treated as suspect. As added security, remember to use tokens to guard against CSRF.

Is the span tag even likely to change CSS class? Because if not, why are you storing the whole tag? Why not just the time (and class)?

Good practice not to store unnecissary stuff in your DB when it can be done later.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.