Omzy Posted December 23, 2008 Share Posted December 23, 2008 function goto(url) { var selection = document.getElementById('region'); if(selection.value != null) { document.location = url + document.getElementById('region').options[document.getElementById('region').selectedIndex].value; } } <a href="/directory/'.$index.'/" onclick="goto(this.href); return false">'.$cat[$index][2].'</a> 'region' is a drop down box (HTML SELECT). What the function does is append the current value of 'region' to the end of the URL specified in the 'a href'. It does this onclick (not onpage load). I was wondering could the same functionality be achieved using PHP? Perhaps using the header() function? Link to comment https://forums.phpfreaks.com/topic/138231-solved-can-this-javascript-function-be-done-in-php/ Share on other sites More sharing options...
Mchl Posted December 23, 2008 Share Posted December 23, 2008 No. Once the page is displayed, PHP has nothing to do with it. You could of course use AJAX, but that would be overcomplicating things (you would still use JavaScript) Link to comment https://forums.phpfreaks.com/topic/138231-solved-can-this-javascript-function-be-done-in-php/#findComment-722702 Share on other sites More sharing options...
Omzy Posted December 23, 2008 Author Share Posted December 23, 2008 Cheers Link to comment https://forums.phpfreaks.com/topic/138231-solved-can-this-javascript-function-be-done-in-php/#findComment-722707 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.