I am trying to collect value of select box first by using javascript and this stored value i need in php variable for select value from select box second.
Asked
Active
Viewed 59 times
-1
-
you need to use ajax in that case – Yassine CHABLI Apr 02 '19 at 10:44
-
It's not entirely clear what you're trying to accomplish. But in order to send a value to your PHP code that value needs to be sent to the server. Either in a form post, or AJAX, or perhaps a query string value on a redirect. It sounds like you want the user to stay on the same page, so that would mean using AJAX. – David Apr 02 '19 at 10:46
-
I know it is difficult to write a good question. Just remember to keep the title as short as possible and, if you have it, illustrate your question with some real programming code. – KIKO Software Apr 02 '19 at 10:48
-
M totally agreed with you #KIKO Softwaer. my problem is that, I have two select box and both are dynamic, select box1 is for some selection value and select box2's value depend on select box1's value. now i retrive the value on select box1's value by using onchange() function in script but i want this value in PHP variable($abc). – Swatantra Jain Apr 02 '19 at 11:11
-
Thank You to all for your precious help, I used an Ajax code to resolve this problem. – Swatantra Jain Apr 04 '19 at 06:00
1 Answers
0
I was stuck with the same problem. Resolved it with the help of jquery and ajax.
first, collect the data with the help of javascript, then send it to the desired page with the help of ajax, and then redeem it by $this->input->post() or get(), whichever way you like.

Shivanjali Chaurasia
- 15
- 5
-
all good but i don't wanna send data to other page. i want to use this value at the same page – Swatantra Jain Apr 02 '19 at 11:04
-
-
@Danyal Sandeelo- the value of select box 1 will help me to filter data of select box 2, so i tried it by onchange function(). value of select box 1 is successfully returned by onchange function but this value is in form of function variable[var x=document.getElementById("mediatype"); var strUser = x.options[x.selectedIndex].text; ] but i need this value in PHP variable like("$abc" variable) – Swatantra Jain Apr 02 '19 at 11:32
-
you will have to make an ajax call after selecting value 1 from combo 1, get all the json of values for combox 2, set all the values to combox 2 … these are basically dependent dropdowns, the second one is dependent on 1st one. – Danyal Sandeelo Apr 02 '19 at 12:43
-
Thank You to all for your precious help, I used an Ajax code to resolve this problem. – Swatantra Jain Apr 04 '19 at 06:00