jquery and CI |
[eluser]mehwish[/eluser]
hi, Can anyone tell me where a .js file is placed and how to load a .js file or how to call it from controller and how to return values from any function of jquery to controller like we do with controller and model (as we call a model's function and when that model's function returns a value we place it in a variable)
[eluser]Amitabh Roy[/eluser]
check this thread http://ellislab.com/forums/viewthread/172363/ this should help you to set up jquery and js files Passing values from jquery to controller can be done by various methods, it depends in which context you are asking. If you can elaborate more it would be helpful. I generally pass values from jquery to CI controller's using the $.ajax method Code: serverData = some field values in firm of query string; http://ellislab.com/forums/viewthread/190618/ You can check this post too http://ericlbarnes.com/blog/post/codeign..._with_ajax
[eluser]mehwish[/eluser]
I can expalin my context to you please consider it and tell me the solution. Actually i have a controller "my_controller" and from it i am loading view "my_view" and i have also included some jquery functions in "my_view" like this: my_view.php Code: <html> now I want to return "m" and "counter" values so that i can access them through my controller or if not from controller atleast i can echo "m" and "counter" outside the script tag in the same view file. I hope you got my point ... please tell me how it can be done ?
[eluser]Amitabh Roy[/eluser]
You are setting the values of counter and m. And you have defined them as javascript variables. For a more convenient programming I think it would be a better option to define them as hidden fields Code: <input type='hidden' value='' id='m'> In this way you can access the m and counter values more efficiently Code: $(document).ready(function() { Now you can access the hidden fields m and counter from anywhere in the view using jquery. Code: $('#counter').val(); of the hidden fields m and counter to the server as parameters in the ajax call.
[eluser]mehwish[/eluser]
but how will i update the hidden text fileds of id "m" and "counter" ? and what is the use of simple this statement: Code: $('#counter').val(tempCounter++);
[eluser]mehwish[/eluser]
ohh yeah yeah i think i got from this simple statement hidden fields' id is being updated .. right ?
[eluser]Amitabh Roy[/eluser]
yep, it can be expanded like this Code: var tempCounter = $('#counter').val(); it updates the value of the counter field and Code: $('#m').val(tempM); updates the value of the m field
[eluser]mehwish[/eluser]
but one thing more i am updating the hidden fields but there is one other text bar in which i have to take input from user so how do i save that value ? as shown in my code that when a user clicks a button (with id="addButton") that text field is generated with default value i have set but i want user to enter his own value and i need to save that user's value not the one set by me .. how can i do this? Hope you understood what i have said
[eluser]Amitabh Roy[/eluser]
I tried to figure out what you meant , but am not sure I understood you fully, so if you can elaborate more, it would be great. What I understood is , when one clicks the add button a textfield is generated with a given value. Code: $(this).before('<input type="textbox" name="textbox' + tempCounter + '" id="textbox' + tempCounter + '" value="textbox'+ tempCounter + '" /><br/>') and you need to correct the html a bit, the input type of textfield is text , so it should be Code: $(this).before('<input type="text" name="textbox' + tempCounter + '" id="textbox' + tempCounter + '" value="textbox'+ tempCounter + '" /><br/>') Now you can set the value blank when you generate the textfield Code: $(this).before('<input type="text" name="textbox' + tempCounter + '" id="textbox' + tempCounter + '" value="" /><br/>') User can fill up their own value here, and to save it , you will need to either submit the form via POST or make an ajax POST call to the server and pass the data so that it can be handled by a CI controller at the server end.
[eluser]mehwish[/eluser]
all i have done thans alot for your help one thing more actually i have a value which is generated inside a for loop consider this: Code: [removed] as you can see "msg" values are being updated after every cycle of for loop and using Code: $('#msg').val(msg); how to pass the all values to controller ... can I directly pass the "msg" value to database from inside the for loop like is: Code: [removed] Or is there any other way to accomplish this? |
Welcome Guest, Not a member yet? Register Sign In |