Jump to content

Drop down with Submit button


Recommended Posts

I'm new to programming in general and am attempting to learn java script. I've been searching the internet trying to find the answer to this and I can not. I've learned how to use a text input with a submit button to collect and use data from a user. I've been trying to get a dropdown menu <select> </select> to take data from a user with the submit button. I know how to make the menu and populate it, but not with an array yet. Can anyone give me some advice on how to make this work? the tutorials on this site have helped but I can not get a good result. <html><head> <title>Another Test</title><script type="text/javascript"> function checkYear(theYear){if (theYear == 1985){alert ("it works");}else{alert ("broken");}} </script> </head> <body> <form method="POST" name="yearForm" onSubmit="checkYear(document.yearForm.theYear);"><select name="theYear" id="idYear" value="year"><option value="1985">1985</option><option value="1986">1986</option></select> <input type="submit" name="submit" value="submit" /> </form> </body</html>

Link to post
Share on other sites
You have told it what form object to look at! but not the important part the value selected
function checkYear(theYear){if (theYear.value == 1985){alert ("it works");}else{alert ("broken");}}

Does the <select> tag have value attr? Not aware of that!
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...