spires Posted October 25, 2010 Share Posted October 25, 2010 Hi Everyone. I'm working on a form, that allows the user to select the country / county / area where they are from. I am doing this using: - mysql database store the locations in - PHP OOP, to pull this information from the database - AJAX/Javascript to only show the next dropdown, once the first dropdown has been selected. Example: select country then the county dropdown will appear, select county then the area/town will appear. However, the first drop down for country is placed directly on to the page. So the javascript works fine. but the second dropdown is placed in to a PHP function, and the javascript seems to no longer want to work. CODE: //////////////// CODE FOR COUNTRY /////////// if(isset($_REQUEST['country'])) { echo ' <div class="labelleft">County / State:</div> <div class="fieldleft"> <div > <select name="county" id="county" onchange="javascript:AJAXQuery("lib/search.php?town="+this.value, "tw", "")"> <option value="0">Select County</option> <option value="0">-------</option>'; $countyList = Area_county::find_country_id($_REQUEST['country']); foreach($countyList as $countyLists){ $county_id = $countyLists->id; $county_list = $countyLists->county; echo '<option value="'.$county_id.'">'.ucwords($county_list).'</option>'; } echo ' </select> </div> </div> <div class="clear"></div>'; } Any ideas? Thanks Link to comment https://forums.phpfreaks.com/topic/216761-help-with-javascript-inside-a-php-function/ Share on other sites More sharing options...
mentalist Posted October 25, 2010 Share Posted October 25, 2010 When making an AJAX call you will need a return handler to get the result, and use more JS to update the HTML in the page. Sorry, this is in the wrong forum... It's an AJAX question and should be in that forum! Link to comment https://forums.phpfreaks.com/topic/216761-help-with-javascript-inside-a-php-function/#findComment-1126115 Share on other sites More sharing options...
unistake Posted October 25, 2010 Share Posted October 25, 2010 I need to create a 4 stage multidrop down as you have described from a mysql db. Can you suggest a good tutorial for it? Thanks Link to comment https://forums.phpfreaks.com/topic/216761-help-with-javascript-inside-a-php-function/#findComment-1126121 Share on other sites More sharing options...
mentalist Posted October 25, 2010 Share Posted October 25, 2010 I think you should get a comfortable understanding of the use of AJAX first, the rest will come naturally... Here's how I use AJAX... http://www.rawstar7.co.uk/docs/cat/203 Link to comment https://forums.phpfreaks.com/topic/216761-help-with-javascript-inside-a-php-function/#findComment-1126128 Share on other sites More sharing options...
unistake Posted October 25, 2010 Share Posted October 25, 2010 ok thanks. Link to comment https://forums.phpfreaks.com/topic/216761-help-with-javascript-inside-a-php-function/#findComment-1126129 Share on other sites More sharing options...
vichu.1985 Posted October 25, 2010 Share Posted October 25, 2010 Dude, The issue is Default JS wont work with the Dynamic form Elements....... I mean to say that, the second drop down is dynamic here. You cant apply any Loaded JS like on change of the values, do something or blah blah...... You can try with the following manner.... While you are loading the second drop down, add an event function on Change of that... like render the second drop down as follows: <select name="second" onchange="return call_JS_function_for_AJAX_Call_Or_Something_Else()" > <option>1</option> <option>2</option> </select> In that JS function write ur logic...... Link to comment https://forums.phpfreaks.com/topic/216761-help-with-javascript-inside-a-php-function/#findComment-1126132 Share on other sites More sharing options...
mentalist Posted October 25, 2010 Share Posted October 25, 2010 Just while looking for another example I found this tutorial in the code snippets forum here at phpfreaks... http://www.phpfreaks.com/forums/index.php/topic,155984.0.html Link to comment https://forums.phpfreaks.com/topic/216761-help-with-javascript-inside-a-php-function/#findComment-1126151 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.