Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    117
    Thanks
    14
    Thanked 0 Times in 0 Posts

    jquery: toggle an input value??

    Hi,

    this thread is related to the previous thread I have made on here,
    http://www.codingforums.com/showthre...672#post926672

    I managed to add a new value to the existing value of the input,

    Code:
    function autofill() {
    		$('.items-form a').click(function(){
    			var currentValue = $("#inputString").val();
    			var newValue = $(this).attr('href') + " ";
    			var totalValue = currentValue + newValue;
    			$("#inputString").val(totalValue);
    			$(this).toggleClass('clicked');
    			return false;
    		});
    		
    	}
    now the problem is how I can 'toggle' the input like we have the toggleClass() in jquery?

    the idea is to remove the input value which I previously add in if I do a second click, but this value will be added again when I do a third click, and go on and on - it is like what toggleClass() does.

    Is it possible?

    here is the link to check the code above if I am not explaining it well...http://lauthiamkok.net/tmp/jquery/to...gle_input.html

    many thanks,
    Lau

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    I'd just split the current input contents into an array and loop through it building an output array - if the clicked href value is in there, don't add it; if it is, do.

  • #3
    Regular Coder
    Join Date
    Dec 2008
    Posts
    117
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Spudhead View Post
    I'd just split the current input contents into an array and loop through it building an output array - if the clicked href value is in there, don't add it; if it is, do.
    i have thought of that but i have no idea how to loop through the split array...

    Code:
    var currentArray = currentValue.split(' ');
    any ideas...?

    thanks,
    L

  • #4
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts

  • Users who have thanked Spudhead for this post:

    lauthiamkok (02-26-2010)

  • #5
    Regular Coder
    Join Date
    Dec 2008
    Posts
    117
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Spudhead View Post
    thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •