Getting value from a javascript variable into a php variable??? |
[eluser]Roy MJ[/eluser]
Hi, Can anyone help me in telling me how to get a javascript variable to transfer its value to a variable in php.??? I used a javascript for a multiple select box and the multiple selection is working fine. But i dunno how to get the value from the javascript variable which stores the result. My controller looks like this : Code: function add(){ My model page looks like this : Code: function save($type='',$field='') And my view looks like this : Code: <head> I am not able to post the javascript linked with it. This forum is showing one error. The save part of the script is shown below: [/code] The final result is stored in the variable strValues i think. But i cannot find a way as to get the result into a variable outside the script so that the i can add the data obtained into the database. Please help..
[eluser]Roy MJ[/eluser]
var strValues = ""; var boxLength = document.choiceForm.destination.length; var count = 0; if (boxLength != 0) { for (i = 0; i < boxLength; i++) { if (count == 0) { strValues = document.choiceForm.destination.options[i].value; } else { strValues = strValues + "," + document.choiceForm.destination.options[i].value; [removed](strValues); } count++; } } alert("Here are the values you've selected:\r\n" + strValues);
[eluser]Atharva[/eluser]
If you want to store the value into database, you will need to use Ajax. Use jQuery. jQuery Ajax
[eluser]Roy MJ[/eluser]
Can u please tell me something that i can do with the script.. Im not familiar with ajax or javascript. I have used javascripts for like lightbox and stuff.
[eluser]Atharva[/eluser]
Another way is to store the JavaScript variables in hidden fields, and submit the form in javascript, so that they can be accessed via $_GET or $_POST in a php script.
[eluser]Roy MJ[/eluser]
Will this work? <input type='hidden' name='des' value='strValues'>
[eluser]Atharva[/eluser]
[quote author="Roy MJ" date="1294745210"]Will this work? <input type='hidden' id='des' name='des' value='strValues'>[/quote] Nope Code: [removed]
[eluser]Roy MJ[/eluser]
Im sorry for disturbing so much, but im still only learning my way with these scripts. I have tried including the above script to the javascript and tried calling using $_GET['des']; But now its showing error: A PHP Error was encountered Severity: Notice Message: Undefined index: des Filename: admin/tour_packages.php Line Number: 27 A PHP Error was encountered Severity: Warning Message: Cannot modify header information - headers already sent by (output started at /home/edatour/public_html/soumya/system/libraries/Exceptions.php:164) Filename: helpers/url_helper.php Line Number: 588
[eluser]Atharva[/eluser]
I don't see <form> in your view so can't tell which method you are using. If it is post, then you can access it by Code: $this->input->post('des') Code: function xyz($des){} so that you can access 'des' as a uri segment. P.S : Though I mentioned $_GET in my earlier post, it is not allowed in CI and it gets filtered out.
[eluser]Roy MJ[/eluser]
Thanks a lot for your time. But im still stuck with this. The olny value thats getting added into my database is 0 and nothing else.. Im looking to do something else for the time.. |
Welcome Guest, Not a member yet? Register Sign In |