Results 1 to 4 of 4

Thread: Input text value problem

  1. #1
    Join Date
    Nov 2009
    Posts
    359

    Input text value problem

    Hi
    I am trying to do a javascript program. My a trying a program such that, when i call the chg() method it applies only second element that is link2. Actually I want is, when I click the link, the name of the link should be displayed in the text field. Any one knows how to do this. Please help. I am posting my code please have a look on it.
    Code:
    <form>
    <a id="static" href="scadmin.ioml">link1</a></br>
    <a id="static" href="scadmin.ioml">link2</a></br>
    <input type="text" id="spec" name="content"/>
    </form>
    <script>
    	var a = document.getElementsByTagName("a");
    	for(var i=0;i<a.length;i++){
    			a[i].href="#";
    			var ale = a[i].innerHTML;
    			a[i].onclick =chg(ale);
    	}
    	
    	function chg(object){
    		var inputobj = document.getElementById("spec"); 
    		inputobj.value = object;
    	}
    </script>
    Any advice or suggestion on this.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Input text value problem

    Hi
    Your function will start running when the page will be loaded, so you are not really calling the function. I observed that inside the loop you are changing the href attribute to a hash. So, I have modified you code, please have a look on it and try it at your side. if any problems do post back.
    Code:
    <form>
    <a  onclick="chg(this)" id="static" href="#">link1</a></br>
    <a  onclick="chg(this)" id="static" href="#">link2</a></br>
    <input type="text" id="spec" name="content"/>
    </form>
    <script>
    	function chg(object){
    		var inputobj = document.getElementById("spec");
    		inputobj.value = object.innerHTML;
    	}
    </script>

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Input text value problem

    Hi
    I have an other alternative for this, but I am not sure it will work with old javascript. But this definitely works if you are using mootools. check out the part of a code below
    Code:
    $$('a').set('href', '#').addEvent('click', func() {
        $('spec').set('value', $(this).get('html'));
    });
    Hope this may help you. Feel free to post your queries. We will be with a answer.

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: Input text value problem

    Hi
    The above posts would have solved your problem. I would like to suggest you that, in your program you are using a loop, do not use it because the loop ends on second link. Here what happens is the first one is replaced by the second. Hope you have solved your problem. If not post back with a query.

Similar Threads

  1. Need to read input text and write it to output file
    By Tramba-keshwar in forum Software Development
    Replies: 6
    Last Post: 26-06-2011, 10:38 PM
  2. JTextArea for input text from the user
    By liatB in forum Software Development
    Replies: 1
    Last Post: 17-03-2010, 08:37 PM
  3. Check multiple text box input
    By GlassFish in forum Software Development
    Replies: 2
    Last Post: 24-11-2009, 01:23 PM
  4. Setting input text values
    By Solaris in forum Software Development
    Replies: 3
    Last Post: 23-11-2009, 02:42 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,433,125.21766 seconds with 16 queries