0

I was trying to add links into javascript but could not do it. Loober is checking an input box. According to the focus, i wanted to change the links that appear on the page. changeME is default.

      <script type = "text/javascript">


    var check = document.getElementById("loober");
    var testElement = document.getElementById("changeMe");
    var text = "bbb";
    var text2 = "aaa";

             check.onfocus= function()
           {
            testElement.innerHTML = text.link("index.php");
        }
          check.onblur = function()
         {
    testElement.innerHTML = text2.link("home.php");
}



</script>

Thanks

7
  • 1
    It works here: jsfiddle.net/dKH2X . What is the behavior you are observing? Commented Aug 18, 2011 at 23:43
  • yes, it shows the links but when i click it says no permission to access this page Commented Aug 18, 2011 at 23:47
  • What is the directory structure of index.php compared to the page you've shown us? Commented Aug 18, 2011 at 23:50
  • oh, ok.Solved now,thanks a lot:) Commented Aug 18, 2011 at 23:56
  • But, i now recognized another problem.I could not click "text". Because when i click it, it loses focus and the blur works.So it disappears.How can i click it?:( Commented Aug 19, 2011 at 0:00

1 Answer 1

2

In answer to your second problem, you can set a short timeout to change the link:

check.onblur = function() {
    setTimeout( function() {
        testElement.innerHTML = text2.link("home.php");
    }, 250);
}

The code calls an anonymous function after 250ms that will return the link to the "blur" link. It should give the user enough time for the link's click event to register. You can change 250 to suit your needs after testing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.