123456 Posted March 7, 2007 Share Posted March 7, 2007 hi all, i really need urgent help ... i have select option on my website.When i choose select option the value of selecet option which i get in the javascript want to assign to PHP variable .So that i can use that in the query. Urgent reply is always appriciated Link to comment https://forums.phpfreaks.com/topic/41584-assign-javascript-variable-to-php-variable/ Share on other sites More sharing options...
skali Posted March 7, 2007 Share Posted March 7, 2007 You will need to refresh your page and send the value of selection option in the URL. This can be achieved through javascript : var selected_value = document.your_form.select_name.options[document.your_form.select_name.options.selectedIndex].value; location = 'abc.php?id='+selected_value; Now on php page you can use php code: <?php echo $_GET['id']; ?> Link to comment https://forums.phpfreaks.com/topic/41584-assign-javascript-variable-to-php-variable/#findComment-201539 Share on other sites More sharing options...
123456 Posted March 7, 2007 Author Share Posted March 7, 2007 Thanks for ypur reply ... but i dont want to refresg th page .i want to do all this without refresing page. Is there any otherv option to do this? Link to comment https://forums.phpfreaks.com/topic/41584-assign-javascript-variable-to-php-variable/#findComment-201546 Share on other sites More sharing options...
todayme Posted March 7, 2007 Share Posted March 7, 2007 I tried to do this using Javascript I could get the value of the dropdown boxes but couldnt pass them to php. Someone kept on saying AJAX LOL. Link to comment https://forums.phpfreaks.com/topic/41584-assign-javascript-variable-to-php-variable/#findComment-201551 Share on other sites More sharing options...
OOP Posted March 7, 2007 Share Posted March 7, 2007 As far as I know you can not assign the result of client side script to a server side script unless you make a new request to the server. Link to comment https://forums.phpfreaks.com/topic/41584-assign-javascript-variable-to-php-variable/#findComment-201597 Share on other sites More sharing options...
Jenk Posted March 7, 2007 Share Posted March 7, 2007 As far as I know you can not assign the result of client side script to a server side script unless you make a new request to the server. Correct. Link to comment https://forums.phpfreaks.com/topic/41584-assign-javascript-variable-to-php-variable/#findComment-201600 Share on other sites More sharing options...
nloding Posted March 7, 2007 Share Posted March 7, 2007 Javascript is exclusively on the client end (the users computer) and PHP is on the server end exclusively (the server itself) and they do not interact backwards -- that is, the server sends scripts to the client, but not the other way around. You either have to use the javascript URL method posted above, or use ajax, where you're making a call using that URL method, but only refreshing a <div> or <span>, not the entire page. If you have to have it with no page refreshes, then you need to use Ajax. Check out the Apress book "Beginning Ajax with PHP From Novice to Professional" ... it explains how to create Ajax objects and how to use them with PHP to query databases and such. Link to comment https://forums.phpfreaks.com/topic/41584-assign-javascript-variable-to-php-variable/#findComment-201622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.