Welcome Guest, Not a member yet? Register   Sign In
how to generate a variable and pass it from view to controller?
#11

[eluser]pistolPete[/eluser]
The hidden input field does not have an id, so you can't use getElementById.

html:
Code:
(...)
<td>:::
        <div id="precio_total">0</div>
        
        &lt;input type="hidden" name="preciott" id="preciott" value=""&gt;
        </td>
      </td>
(...)

js:
Code:
(...)
totalT = totalT.toFixed(2);
document.getElementById("precio_total").value = totalT;
document.getElementById("preciott").value = totalT;
(...)

Some general questions:
- Why don't you use a javascript library like jQuery? It really simplifies javascript.
- What is your script doing at all? Are you calculating prices via javascript? This can easily be changed on the client side!
#12

[eluser]pistolPete[/eluser]
sorry, double post
#13

[eluser]ValdemarDeMatos[/eluser]
Well, I'm starting with this php and javasript thing.
So I was needing to make a form that calculates the prices of some products based on the quantity that the user inputs.

As I'm not very familiar whith the javascipt frameworks so I hardcode it myself (the way I could).
Due to my inexperience I've done it like this.

...

This is like a sacrileg, right?
#14

[eluser]ValdemarDeMatos[/eluser]
What do you mean when you say that 'This can easily be changed on the client side'?
#15

[eluser]pistolPete[/eluser]
If you do your calculations in javascript and then send that value to the server, a "hacker" can change the value before it is sent.
E.g. he could change the total price to "0" and he would get everything for free.

There is a Cart library for CodeIgniter in the svn repository, which you could have a look at: Cart.php
#16

[eluser]TheFuzzy0ne[/eluser]
Basically, you can do your calculations on the client side for customer convenience, but don't assume you're getting the right value back on the server. Always double-check your data. If the user doesn't have JavaScript enabled, the the calculations will not take place either.
#17

[eluser]ValdemarDeMatos[/eluser]
Although this is 'closed' clients circuit, you are obviously right.


Is this Cart Class you're showing me, related to this:

http://locomotiva-assets.com/user_guide/.../cart.html

?
#18

[eluser]pistolPete[/eluser]
Yes this is the user guide from svn which isn't available on codeigniter.com yet, since 1.7.2 has not been released.
#19

[eluser]ValdemarDeMatos[/eluser]
Well... let's remake it in an all new way!
We have to suffer to learn. :blank:
I think I'm going to need you again in a near future.
I hope i'll be more prepared then.

Thank so much pistolPete for your precious advices and for wasting your time with a newbie like me :red:
Thank you also TheFuzzy0ne.
#20

[eluser]TheFuzzy0ne[/eluser]
It's only a waste of time if no progress is made, otherwise, it's time well spent.




Theme © iAndrew 2016 - Forum software by © MyBB