0

I want to disable the jQuery event if a Text box is in focus. I am using following code. If a user is entering any text in text field then if by change the cursor moves to the image then it will reset the text in text field to the value shoot by event. I don't want to the event to execute if text field is in focus.

<!DOCTYPE html>
<html>
<head>
  <style>span {display:none;}</style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <input type="text" id="team" /> 

<script>
$("input").focusin(function() {

    document.getElementById("team").value = "I am in Focus Dont shoot events PLZ";

    }

);

$(document).ready(function() {
    $("img").mouseover(function(event) {
        if(event.target.name != '')
            {   

        document.getElementById("team").value = event.target.name;


            }

        //alert(event.target.name);
    });
});
</script>

<img src="http://1.bp.blogspot.com/-bVD6mGlH_ik/TnHV75bw9KI/AAAAAAAAB84/1hJU7WJuU8k/s400/fewr.jpg" name="I" />


</body>
</html>

I have already tried following function

$("input").focusin(function() {
        document.getElementById("team").value = "I am in Focus Dont shoot events PLZ";
        });

Now I am using below code but still not working. Please help me.

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<img src="http://1.bp.blogspot.com/-bVD6mGlH_ik/TnHV75bw9KI/AAAAAAAAB84/1hJU7WJuU8k/s400/fewr.jpg" name="Ihhhhhhhhhhhhhhh" id="myimage" />
<input id="theone">

<input type="image" src="http://www.clker.com/cliparts/e/2/a/d/1206574733930851359Ryan_Taylor_Green_Tick.svg.thumb.png" id="bind">
<input type="image" src="http://www.clker.com/cliparts/4/3/1/f/1195436930767206781not_ok_mark_h_kon_l_vdal_01.svg.thumb.png" id="unbind">





<script>

  $("#unbind").click(function(event) {
  $("img").off();
  alert("off");
  });




  $("#bind").click(function(event) {
   $("img").on();
   alert("on");
  });


  $("img").mouseover(function(event) {
    if(event.target.name != '')
        {
         document.getElementById("theone").value = "done";
        }
    //alert(event.target.name);
});



</script>

</body>
</html>
Brian Tompsett - 汤莱恩
  • 5,195
  • 62
  • 50
  • 120
i.jolly
  • 51
  • 2
  • 9
  • be specific about your requirement. dont understand what you want.. – Paresh Balar Mar 17 '12 at 07:44
  • after page load value of image name is entered to textbox. But i want to disable this thing when that text box is in focus. and also reactive this thing after focus is out from text field. hope u understand PLZ help – i.jolly Mar 17 '12 at 07:53
  • yup.. got your requirement... check answer that i posted in comment.. – Paresh Balar Mar 17 '12 at 08:52

1 Answers1

4

Just put one condition in mousehover event...

Enter Text in text box if textbox is not focus using this code !$("#team").is(":focus")

here is the demo : http://jsfiddle.net/s8zxY/1/

Paresh Balar
  • 360
  • 2
  • 9
  • THANKS :) Its workING>>> Dude thanks A LOT. was hitting walls from past 2 days ..... http://jsfiddle.net/EKSJX/2/ – i.jolly Mar 17 '12 at 09:27
  • Done Yeah ! thanks again .Ok tell me is there any thing to show progress bar on image load. Or any script to load images fast by redusing its size or by interlacing ??? now when i click add Quetion it shows"Sorry, we are no longer accepting questions from this account. See http://goo.gl/C1Kwu to learn more." – i.jolly Mar 17 '12 at 11:37