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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    117
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Jquery: adding input values each time on top when click

    Hi,
    I am trying to write this code which the value in the input field can be added on top each time when you get the value from links,

    Code:
    $(document).ready(function(){	
    	autofill();
    });
    
    function autofill() {
    		$('.items-form a').click(function(){
    
    			var str = "";
    			str += $(this).attr('href') + " ";
    			$("#inputString").val(str);
    
    			return false;
    		});
    	}
    Code:
    <input type="text" size="30" value="" id="inputString" />
    
    <div class="items-form">
    	<a href="arts">Arts</a>
    	<a href="design">Design</a>
    	<a href="vectors">Vectors</a>
    	<a href="games">Games</a>
    	<a href="science">Science</a>	
    </div>
    what this code does so far is that it only change the value inside the input field each time I click on another links... what i have missed...?

    any ideas will be much appreciated.

    many thanks,
    Lau

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,478
    Thanks
    6
    Thanked 981 Times in 954 Posts
    I’m not quite sure yet what you want. Do you mean you want to add a new input to the existing one(s) each time an anchor is clicked with the respective value filled in?

  • #3
    Regular Coder
    Join Date
    Dec 2008
    Posts
    117
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by VIPStephan View Post
    I’m not quite sure yet what you want. Do you mean you want to add a new input to the existing one(s) each time an anchor is clicked with the respective value filled in?
    hi there!
    yes you are right. for instance, i might have a few existing values (which I might pull from a database) already in that input field like this -

    'jquery php'

    then when I add a new input value which I am taking it from the <a> tag to this existing ones, it will be look like this,

    'jquery php science arts'

    is it possible?

    thanks.
    Last edited by lauthiamkok; 02-25-2010 at 05:13 PM.


  •  

    Posting Permissions

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