Advertisement
andrewb

select_test.html

Jan 14th, 2015
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.60 KB | None | 0 0
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html lang="en">
  3. <head>
  4.     <title>Select Test</title>
  5.     <script type="text/javascript">
  6. // <[!CDATA[
  7.  
  8. function AddName() {
  9.    var name = document.getElementById("txtNewName").value;
  10.    if (name=="") { return; }
  11.    var node = document.createElement("option");
  12.    var text = document.createTextNode(name);
  13.    node.setAttribute("value", name);
  14.    node.appendChild(text);
  15.    document.getElementById("ddNames").appendChild(node);
  16.    document.getElementById("txtNewName").value = "";
  17. }
  18.  
  19. function SetName() {
  20.    var selected = document.getElementById("ddNames").selectedIndex;
  21.    var thelist = document.getElementById("ddNames").options;
  22.    if (selected < 1) { return; }
  23.    document.getElementById("hidName").value = thelist[selected].value;
  24.    document.getElementById("ddNames").selectedIndex = 0;
  25. }
  26.  
  27. function ShowName() {
  28.    var name = document.getElementById("hidName").value;
  29.    alert(name);
  30. }
  31.  
  32. // ]]>
  33.     </script>
  34. </head>
  35. <body>
  36.     <p>
  37.         Add a name:
  38.         <input type="text" id="txtNewName" value="">
  39.         <input type="button" id="btnAddName" value="Add Name" onclick="AddName()">
  40.     </p>
  41.     <hr>
  42.     <select id="ddNames">
  43.         <option value="">Choose a name...</option>
  44.     </select>
  45.     <input type="button" id="btnSetName" value="Set Name" onclick="SetName()">
  46.     <hr>
  47.     <input type="hidden" id="hidName" value="">
  48.     <input type="button" id="btnShowName" value="Show Name" onclick="ShowName()">
  49.     <script type="text/javascript">
  50. // <[!CDATA[
  51.  
  52. // ]]>
  53.     </script>
  54. </body>
  55. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement