Jump to content

Problems with onfocus


Shadowing

Recommended Posts

Hey guys im having a issue with using onfocus with some ajax code I have a input field that im changing its value every time a user clicks a link using ajax on page load the value in the input field is say "1" then I click the link and the ajax changes the input field to "2"

$('.sector_input_y').val(response.current_y);

then using this function i made it activates the onfcous so the text goes away when you click on it and then comes back when you click off it.

 function onfocus_text(tag,text){ $(tag).each(function() {    text = this.value;    $(this).focus(function() {	    if(this.value == text) {		    this.value = '';	    }    });    $(this).blur(function() {	    if(this.value == '') {		    this.value = text;	    }    });});    }

The problem is when i click on the input field then off it it returns to the value of 1 instead of 3 so the variable current_y isnt holding the value that ajax changed it too.

$("#up").click(function(event) {		  event.preventDefault();$.ajax({		      url: "<?php echo LPATH; ?>ajax/map.php?functions=up",		      type: 'POST',		      dataType: 'json',		      data: { },		   	success: function(response) {			 		  var current_y = (response.current_y);	 $('.sector_input_y').val(response.current_y); 	 onfocus_text('.sector_input_y',current_y);	 }	 });});

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...