Welcome Guest, Not a member yet? Register   Sign In
Dynamic forms
#1

[eluser]hostingx[/eluser]
Hello,

I'm busy with creating a incoice system,

When you create your invoice, you have to select a specific product, so the prices etc, are automaticly updated etc..

These items comes from a database, is there any way to solve this? i guess i have to use AJAX, but does any of you guys have a sample script or something?

Thanks in advance!
#2

[eluser]Aea[/eluser]
Yea it's pretty much an AJAX question, how you go about it is really up to you. I personally use prototype, you have an listener for a change in a drop down (which would have it's own unique ID to reference), then the JS sends a request to the server which will respond with the values you want to fill in, personally I would use JSON, but you can send pure HTML to inject if that's your preference. You could have a controller named Ajax and just send the type of requests you want to do, ie ajax/form_get_item/ and send any variables you need as a POST.

The other way to do it would be to pull any possible result directly into the page (or in an external .js) and skip the database call since the client would have any information to add, of course this only works if your database is small, and if it isn't updated often so you can create the script files storing the data, personally this is... ugly, but it doesn't require AJAX Smile
#3

[eluser]hostingx[/eluser]
Hi,

thanks for you reply, i tried to figure it out using JSON, but i cant get the clue about what you mean :o

Can you please post an example about what you mean?
#4

[eluser]Aea[/eluser]
Say you add something to your cart and then you get options for color, size, etc. You perform the addition using AJAX already, now you have to request the options from the client side. The server (PHP) creates an array containing all the information you want and uses json_encode on the output. I'm sure you could use a CI view here, just modify the header to the proper JSON type and you can send JSON in either the header or the body, the latter doesn't have a pesky size limit so work with that. On the client side all you have to do is receive the output as a JSON object (If you're using prototype I can dig up some examples), and then it's simply a matter of putting in the data from the JSON object into a form / etc you want to work with. Oh, and good luck finding examples with working with JSON, it's powerful but horribly under documented for such a simple tool Smile




Theme © iAndrew 2016 - Forum software by © MyBB