jimbo1978 Posted March 3, 2006 Share Posted March 3, 2006 Hi all,Im fairly new to Javascript been using this site as reference. Anyway I have been trying to create a site in which I can select a region and receive information relating to the region selected. At the moment I have tried to keep it simple so that I can see that it is working correctly. The idea is that the site loads and from the drop down list you select a region and the function engSelect() takes the value and sends output back depending on what you have selected. I am having a problem passing the value from the menu form to the function. I have tested the function and it appears to be working ok. Please help. Thanks. Below is the code.<html><head><title>Select Engineering Group</title><script type="text/javascript">function engSelect( rgn) {var area = rgn;if (area == 1) { return area + "one";} else if (area == 2) { return area + "two";} else if (area == 3) { return "three";} else { return "None";}//end if}//End engSelect</script></head><body><br>Please select a regional team:<p><form> <select name="rgn"> <option value = "1">North West</option> <option value = "2">North East</option> <option value = "3" selected="selected">West Midlands</option> <option value = "4">South East</option> <input type="button" value="Submit" onclick="engSelect( rgn)"> </select></form><p><script type="text/javascript"> document.write( engSelect());</script></body></html> Link to comment Share on other sites More sharing options...
scott100 Posted March 3, 2006 Share Posted March 3, 2006 try this with some minor mods, you weren't actually passing a value to the function, just the object. I've not returned anything either just wrote it from withing the function using innerHTML <html><head><title>Select Engineering Group</title><script type="text/javascript">var area;function engSelect(rgn) {if (rgn==1) area="one";else if (rgn==2) area="two";else if (rgn==3) area="three";else if (rgn==4) area="four"; else area="problem";document.getElementById('para').innerHTML=area;}</script></head><body><br>Please select a regional team:<p><form><select name="rgn"><option value="1">North West</option><option value="2">North East</option><option value="3" selected="selected">West Midlands</option><option value="4">South East</option> <input type="button" value="Submit" onclick="engSelect(rgn.value)"></select></form><p id="para"></p></body></html> Link to comment Share on other sites More sharing options...
jimbo1978 Posted March 3, 2006 Author Share Posted March 3, 2006 Great added your code and it is working fine. Thanks for your help. How does the innerHTML work exactly? I would have thought calling doc.write function would have worked to display output. Link to comment Share on other sites More sharing options...
scott100 Posted March 3, 2006 Share Posted March 3, 2006 You can use innerHTML to write to a page or change text already written after a page has been loadedUsing document.write, try it and see what happens, it writes the answer to a blank page, i dont think that was what you were after. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now