shawn10642 Posted December 14, 2008 Share Posted December 14, 2008 I need help with one little code in javascript and a very little in php if some could help? Shawn This is the Form <!-- Forecast Quick Link --> <form id="quickLinkForm" class="hidden" action="POST"> <fieldset id="quickLink"> <legend>Forecast Quick Link</legend> <label class="hidden" for="provinces">Province/Territory names</label> <select onchange="updatecities(this,'en')" size="1" id="provinces"> <option value="--">Select a Region</option> <option value="AB">Alberta</option> <option value="BC">British Columbia</option> <option value="MB">Manitoba</option> <option value="NB">New Brunswick</option> <option value="NF">Newfoundland and Labrador</option> <option value="NT">Northwest Territories</option> <option value="NS">Nova Scotia</option> <option value="NU">Nunavut</option> <option value="ON">Ontario</option> <option value="PE">Prince Edward Island</option> <option value="QC">Quebec</option> <option value="SK">Saskatchewan</option> <option value="YK">Yukon</option> </select> <label class="hidden" for="cities">City/Town names</label> <select size="1" id="cities"> <option selected="selected">Select a Location</option> </select> <input type="button" value="Go" onclick="jumpToCity(cities, provinces, 'metric', 'e')"/> </fieldset> </form> <script type="text/javascript" src="eventLibrary.js"></script> <script type="text/javascript" src="forecastQuickLinkArraysEn.js"></script> <script type="text/javascript" src="forecastQuickLink.js"></script> and this is the section of the javascript function jumpToCity(cityObj, provinceObj, units, lang) { var citycode = cityObj.options[cityObj.selectedIndex].value; var provincecode = provinceObj.options[provinceObj.selectedIndex].value; if (provincecode == "--") { // This means that no province has been selected, so display error message if (document.getElementById('errorMessage')==null) { // only need to display it once var quicklinkObj = document.getElementById('quickLink'); var errorLabel = document.createElement('div'); errorLabel.setAttribute('id', 'errorMessage'); errorLabel.className = 'error'; if (lang == "e") { // display message based on language errorLabel.appendChild(document.createTextNode("Please select a region")); } else { errorLabel.appendChild(document.createTextNode("S.V.P. Choisissez une région")); } quicklinkObj.appendChild(errorLabel); } } else if (lang .selectedIndex == 0 || citycode == 'OLP') { location.href = "/forecast/canada/summary_" + lang + ".html?" + citycode; // display Olympic summary } else { if (units == 'metric') { location.href = "" } else { location.href = "/forecast/city_" + lang + ".html?" + citycode.toLowerCase() + "&unit=i"; // imperial city page } } } 1) You pick ex. Ontario 2) pick Toronto 3) then it will pick a code from an array something like ON-123 4) it then goes to http://www.weatheroffice.gc.ca and gets infomation and posts it on my site This is the script that does that: <table bgcolor="#000000 align="center" width="100%"> <tr> <td bgcolor="#000000" align="center"> <?php include_once("weather.class.php"); $weather = new getWeather(); $weather->dbUser="root"; $weather->dbPass=""; $weather->dbName="db_name"; $weather->cityCode="$city"; echo "<table cellspacing=0 cellpadding=3>"; if ($weather->fetchData()){ echo "<tr><td colspan=3 align=center>\n\n".$weather->showWeather()."\n</td></tr>"; } $weather->cityCode="$city"; $weather->dispFormat=1; if ($weather->fetchData()){ echo "<tr valign=top><td>\n\n".$weather->showWeather()."\n</td>"; } $weather->cityCode="$city"; $weather->dispFormat=2; $weather->longText=true; if ($weather->fetchData()){ echo "<td>\n\n".$weather->showWeather()."\n</td>"; } $weather->cityCode="$city"; if ($weather->fetchData()){ echo "<td>\n\n".$weather->showCurrent()."\n</td></tr>\n"; } echo "</table>"; ?> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/ Share on other sites More sharing options...
shawn10642 Posted December 14, 2008 Author Share Posted December 14, 2008 and what i need help on is on the JavaScript this is the original of the 2nd code: } else if (cityObj.selectedIndex == 0 || citycode == 'OLP') { location.href = "/forecast/canada/summary_" + lang + ".html?" + citycode; // display Olympic summary } else { if (units == 'metric') { location.href = "/city/pages/" + citycode.toLowerCase() + "_" + units + "_" + lang + ".html"; // metric city page } else { location.href = "/forecast/city_" + lang + ".html?" + citycode.toLowerCase() + "&unit=i"; // imperial city page } } } and this little part is where my troubles are: if (units == 'metric') { location.href = "/city/pages/" + citycode.toLowerCase() + "_" + units + "_" + lang + ".html"; // metric city page this is the little the little code citycode.toLowerCase() that gets the array code and i need it to do a $_POST to the weather page Hope Someone Can Help Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/#findComment-715256 Share on other sites More sharing options...
shawn10642 Posted December 15, 2008 Author Share Posted December 15, 2008 Help... Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/#findComment-715575 Share on other sites More sharing options...
shawn10642 Posted December 15, 2008 Author Share Posted December 15, 2008 no replys Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/#findComment-716242 Share on other sites More sharing options...
shawn10642 Posted December 18, 2008 Author Share Posted December 18, 2008 47 view and no help ??? Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/#findComment-719302 Share on other sites More sharing options...
Philip Posted December 19, 2008 Share Posted December 19, 2008 I'm not real sure what your problem is... but I'm going to try: 1) You pick ex. Ontario 2) pick Toronto 3) then it will pick a code from an array something like ON-123 4) it then goes to http://www.weatheroffice.gc.ca and gets infomation and posts it on my site So, this would be more of an AJAX question - since you want to retrieve data from the other website and display it on yours, without refreshing the page. Correct? If so, have ever done any AJAX requests before? If not, maybe you can help me out by explaining the question/problem again Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/#findComment-719363 Share on other sites More sharing options...
shawn10642 Posted February 11, 2009 Author Share Posted February 11, 2009 Sorry this is my old topic but, i still cant figure this out, if anyone can help that would be great. or maybe if someone can help with this problem but make another array. if i can make another array and make more simple, this script is only for canada so it shouldn't be too hard. if anyone can help please reply Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/#findComment-759961 Share on other sites More sharing options...
shawn10642 Posted February 13, 2009 Author Share Posted February 13, 2009 help any one :'( :'( Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/#findComment-761287 Share on other sites More sharing options...
Philip Posted February 13, 2009 Share Posted February 13, 2009 I'm not real sure what your problem is... but I'm going to try: 1) You pick ex. Ontario 2) pick Toronto 3) then it will pick a code from an array something like ON-123 4) it then goes to http://www.weatheroffice.gc.ca and gets infomation and posts it on my site So, this would be more of an AJAX question - since you want to retrieve data from the other website and display it on yours, without refreshing the page. Correct? If so, have ever done any AJAX requests before? If not, maybe you can help me out by explaining the question/problem again Read that, and answer the 2 questions Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/#findComment-761647 Share on other sites More sharing options...
shawn10642 Posted February 13, 2009 Author Share Posted February 13, 2009 Answer: Nope. Ok what this script is supposed to do it 1) enter weather.php <--main weather page 2) there two drop-down forms the first is province and the second is city. Pick your province (in this case Ontario), and then the second form Auto-Fills. Drop the second form and pick your city (in this case Toronto). 3) When you press the Go/Send button, it then goes though that javascript coding (About Posts) and is fetches the City Code from an array (In this case on-123) which is citycode.toLowerCase() from this clips... if (units == 'metric') { location.href = "/city/pages/" + citycode.toLowerCase() + "_" + units + "_" + lang + ".html"; // metric city page 4) In stead of location.href i need it to $_POST to another script (haven't posted the script in the form), which need that on-123 code? any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/#findComment-761698 Share on other sites More sharing options...
Philip Posted February 13, 2009 Share Posted February 13, 2009 Okay, for the first one - it's kinda what I thought it would be. You can find some info on this: http://www.phpfreaks.com/forums/index.php/topic,148399.0.html or http://forums.devshed.com/javascript-development-115/how-to-fill-a-select-menu-from-an-javascript-array-28438.html I don't have any code handy, since I've never actually done it - but i know the concept. That'll take care of 1 & 2. For 3 + 4, take a look at ajax forms. There are tons of examples out there Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/#findComment-761738 Share on other sites More sharing options...
shawn10642 Posted February 14, 2009 Author Share Posted February 14, 2009 :-( i've looked at many....Many forms and still cant do it... i like my php more then ajax/js would you know anyother way of doing this and heres the array sample var citiesEn = new Object(); citiesEn['--']=['Select a Location|']; citiesEn['AB']=["Airdrie|AB-12","Athabasca|AB-10","Banff|AB-49","Barrhead|AB-2","Beaverlodge|AB-57","Bow Island|AB-43","Bow Valley (Provincial Park)|AB-42","Breton|AB-36","Brooks|AB-58","Calgary|AB-52","Calgary (Olympic Park)|AB-61","Camrose|AB-18","Canmore|AB-3", and it goes on like that. This is killing my brain haha Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/#findComment-761757 Share on other sites More sharing options...
shawn10642 Posted February 14, 2009 Author Share Posted February 14, 2009 and its only the little "location.href', i dont need it to redirect it to a different page i need it to, 'when you press the submit button' to stay on the same page, and just $_post the code. a bit confusing... Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/#findComment-761760 Share on other sites More sharing options...
shawn10642 Posted February 14, 2009 Author Share Posted February 14, 2009 Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/#findComment-761777 Share on other sites More sharing options...
shawn10642 Posted February 15, 2009 Author Share Posted February 15, 2009 still unanswered , well partially answered... Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/#findComment-762455 Share on other sites More sharing options...
shawn10642 Posted February 17, 2009 Author Share Posted February 17, 2009 anyone else? willing to help? Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/#findComment-763981 Share on other sites More sharing options...
shawn10642 Posted February 25, 2009 Author Share Posted February 25, 2009 2 weeks and no reply Quote Link to comment https://forums.phpfreaks.com/topic/136950-php-form-javascript-weather-script/#findComment-770855 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.