Jump to content

Java Function


jimbo1978

Recommended Posts

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...