Click here to Skip to main content
15,887,464 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
<head>
<script type="text/javascript">
function wtf()
{
window.alert("wtf???");
}</script>
</head>
<body onload="wtf()><!--{exception}	'wtf' is undefined-->
   Kinds:<select id="Select1" name="D1" onchange="wtf();">
  <option value='1'>1,Platform</option>
   <option value='1'>1,yadda</option>
  </select>Domains
Posted
Updated 15-Aug-14 15:53pm
v6
Comments
[no name] 15-Aug-14 21:58pm    
<body önload="wtf()">

Try this:
XML
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function wtf()
{
   var select = document.getElementById("Select1");
   // get the selected value
   alert(select.value);

   var selectedText = select.options[select.selectedIndex].text;
   // get the selected text
   alert(selectedText);
}</script>
</head>
<body>
   Kinds: <select id="Select1" name="D1" onchange="wtf();">
     <option value='1'>Platform</option>
     <option value='2'>yadda</option>
  </select> Domains
</body>
</html>
 
Share this answer
 
There is nothing to change with just one option in the select element; should be at least two.

But it works for me; there is nothing undefined. You can write alert instead of window.alert. This method present in the window object, so you can use it.

—SA
 
Share this answer
 
So I am the only one that keeps getting the error saying that the function 'wtf'(and every other function I write) is undefined?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900