yoda69 Posted July 1, 2007 Share Posted July 1, 2007 hey, im trying to build a php page which have a javascript for creating 2 dependent dropdown boxes. can anyone tell me how do i transfer a varaible from the java script to the php code? this is the java script: --------------------------------------------------- function GetSelectedItem() { len = document.f1.s1.length i = 0 chosen = "none" for (i = 0; i < len; i++) { if (document.f1.s1.selected) { chosen = document.f1.s1.value } } return(chosen) } ----------------------------------------- the variable is of course: chosen tnx Quote Link to comment https://forums.phpfreaks.com/topic/57960-get-variable-from-a-java-script/ Share on other sites More sharing options...
MadTechie Posted July 1, 2007 Share Posted July 1, 2007 your need to get/post them or use AJAX (maybe cookies) Quote Link to comment https://forums.phpfreaks.com/topic/57960-get-variable-from-a-java-script/#findComment-287259 Share on other sites More sharing options...
yoda69 Posted July 1, 2007 Author Share Posted July 1, 2007 tnx for the reply, doesnt that imply that i will need to use a second webpage? I would like to have the two dropbox on the same page. tnx Quote Link to comment https://forums.phpfreaks.com/topic/57960-get-variable-from-a-java-script/#findComment-287265 Share on other sites More sharing options...
MadTechie Posted July 1, 2007 Share Posted July 1, 2007 i assume you wish to select a option from one drop down, then use that value to control the values in the second drop down.. if thats true.. theirs a few ajax example out their.. Quote Link to comment https://forums.phpfreaks.com/topic/57960-get-variable-from-a-java-script/#findComment-287267 Share on other sites More sharing options...
LuAn Posted July 1, 2007 Share Posted July 1, 2007 doesnt that imply that i will need to use a second webpage? PHP runs on the server and sends it's output to the viewers browser which THEN runs the Javascript. Thus the Javascript can't pass things back to the PHP that created the page. What you can do is to use the Javascript to call another page (or the same page again so that the PHP runs a second time). Alternatively you can use AJAX techniques so that Javascript on the browser gets more data from the server and inserts it into the page without reloading it. Note however that it is the Javascript that is doing the updating. Quote Link to comment https://forums.phpfreaks.com/topic/57960-get-variable-from-a-java-script/#findComment-287272 Share on other sites More sharing options...
Barand Posted July 1, 2007 Share Posted July 1, 2007 If you have a table structure (with numeric keys) like below, where tableA is used to populate the first drop down and tableB is used to populate the second (eg. country/region , car make/model etc) then the baaSelect class in my sig will help. [pre] tableA tableB --------- --------- id (int) ---+ id (int) descrip | descrip +----- a_id (int) [/pre] Or you can use the AJAX approach - see other link Quote Link to comment https://forums.phpfreaks.com/topic/57960-get-variable-from-a-java-script/#findComment-287377 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.