JAVASCRIPT - Customize links based on user button choices


SUBMITTED BY: efbee

DATE: Oct. 3, 2016, 3:51 p.m.

FORMAT: JavaScript

SIZE: 2.0 kB

HITS: 667

  1. <HTML>
  2. <HEAD><TITLE>Choice</TITLE>
  3. <SCRIPT Language="javascript">
  4. // sets up database of links - SECTION A1
  5. muresources=""
  6. muresources["classical"]= "<A HREF='http://net.com/classical.file1'>Meditative classical music<A><P>
  7. <A HREF='http://net.com/classical.file2'>Provoking classical music<A>"
  8. muresources["rock"] = "<A HREF='http://net.com/rock.file1'>Popular rock music<A><P>
  9. <A HREF='http://net.com/rock.file2'>Exciting rock music<A>"
  10. muresources["ethnic"] = "<A HREF='http://net.com/mexican.file1'>Mexican music<A><P>
  11. <A HREF='http://net.com/Indian.file2'>Indian music<A>"
  12. function getLink() {
  13. // constructs unique page using name and choice of music - SECTION A.2
  14. temp = muresources[choice]
  15. temp2 = "<TITLE>Custom Links</TITLE><H3>" +document.m.pername.value+", here are some
  16. links for you</H3><P>"+temp
  17. }
  18. function writeIt(){
  19. // creates new window to display page - SECTION A.3
  20. diswin = window.open();
  21. diswin.document.open();
  22. diswin.document.write(temp2);
  23. diswin.document.close()
  24. }
  25. function doAll(){
  26. // master routine calls other functions - SECTION A.4
  27. getLink();
  28. writeIt()
  29. }
  30. </SCRIPT>
  31. </HEAD>
  32. <BODY >
  33. <!-- Sets up basic input form SECTION B -->
  34. <H3> Choose the kind of music you prefer<BR>
  35. and this page will fetch links of interest to you</H3>
  36. <HR>
  37. <FORM NAME="m" >
  38. Choose a kind of music<P>
  39. <INPUT TYPE="radio" NAME="mus" VALUE="classical" OnClick="choice='classical'"
  40. >Classical <BR>
  41. <INPUT TYPE="radio" NAME="mus" VALUE="rock" OnClick="choice='rock'">Rock<BR>
  42. <INPUT TYPE="radio" NAME="mus" VALUE="ethnic"
  43. OnClick="choice='ethnic'">Ethnic<BR>
  44. <HR>
  45. Please type your name<P>
  46. <INPUT TYPE="text" NAME="pername" SIZE=25>
  47. <HR>
  48. <INPUT TYPE="button" NAME="sub" VALUE="Show me links" OnClick=doAll()>
  49. <INPUT TYPE="reset" NAME="res" >
  50. </FORM>
  51. <SCRIPT>
  52. // sets defaults - SECTION C
  53. choice = "classical"
  54. document.m.mus[0].checked = true
  55. document.m.mus[1].checked = false
  56. document.m.mus[2].checked = false
  57. </SCRIPT>
  58. </BODY>
  59. </HTML>

comments powered by Disqus