code_junkie

javascript select() function with named anchor

Nov 12th, 2011
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <HTML>
  2. <HEAD>
  3. <script>
  4. function setFocus() {
  5. document.AForm.AText.select();
  6. }
  7. </script>
  8.  
  9. </HEAD>
  10.  
  11. <BODY onLoad="setFocus();">
  12. <br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  13. <br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  14. <br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  15. <br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  16.  
  17. <a name="ATag"></a>
  18. <form name="AForm" id="AForm" action="Test.html#ATag" method="get">
  19. <input type="text" name="AText" id="AText" value="Enter text here." >
  20. <input type="submit" value="OK">
  21. </form>
  22.  
  23. </BODY>
  24. </HTML>
  25.  
  26. function setFocus() {
  27. setTimeout(tryFocus,100);
  28. }
  29.  
  30. function tryFocus() {
  31. document.AForm.AText.select();
  32. }
  33.  
  34. <form name="AForm" id="AForm" action="index.html#ATag" method="get" onsubmit="bustCache();">
  35. <input type="text" name="AText" id="AText" value="Enter text here." >
  36. <input type="hidden" name="AHidden" id="AHidden" value="">
  37. <input type="submit" value="OK">
  38. </form>
  39.  
  40. function setFocus() {
  41. setTimeout(tryFocus,100);
  42. }
  43.  
  44. function tryFocus() {
  45. document.AForm.AText.select();
  46. }
  47.  
  48. function bustCache() {
  49. document.AForm.AHidden.value = (new Date()).getTime();
  50. }
Add Comment
Please, Sign In to add comment