Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 23-11-2009
Member
 
Join Date: Apr 2008
Posts: 240
Setting input text values

Hi
I have a problem with my javascript program. I my program I call the function change() it applies only second element that is link2. The result that I want was when I clicked the link the link name should appear in the text field. Does any one know about this. How to do this
Code:
<form>
<a id="static" href="staticContentAdmin.ioml">link1</a></br>
<a id="static" href="staticContentAdmin.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 x = a[i].innerHTML;
a[i].onclick =change(x);
}
function change(object){
var inputobj = document.getElementById("spec");
inputobj.value = object;
}
</script>

Last edited by Solaris : 23-11-2009 at 02:32 PM.
Reply With Quote
  #2  
Old 23-11-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Setting input text values

Hi
I think you are not really calling the function. It is started when the page is loaded. I observed that the href attribute to a hash inside the loop is being changing. So I have done so modification in your program. just go through the program, it will help you.
Code:
<form>
<a onclick="change(this)" id="static" href="#">link1</a></br>
<a onclick="change(this)" id="static" href="#">link2</a></br>
<input type="text" id="spec" name="content"/>
</form>
<script>
function change(object){
var inputobj = document.getElementById("spec");
inputobj.value = object.innerHTML;
}
</script>
</body>
</html>
Try this one and if you have any queries do post back .
Reply With Quote
  #3  
Old 23-11-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: Setting input text values

Hi
The above posted should work fine to your problem. If not I am posting a simple part of code. I think it will surely help you. But I am not sure this work in plain old javascript. Surely this works using mootools though.
Code:
      $$('a').set('href', '#').addEvent('click', function() {
      $('spec').set('value', $(this).get('html'));
      });
Reply With Quote
  #4  
Old 23-11-2009
Member
 
Join Date: Apr 2008
Posts: 240
Re: Setting input text values

Hi
Thank you guys.
Both the posts have helped me a lot. The second one is interesting, I have not tried with the second one. But looks like it is interesting. The first one sure works very fine, no problem with that and is easy to understand. I will soon try with the second code. Thanks again.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Setting input text values"
Thread Thread Starter Forum Replies Last Post
Looking for formula that can ignore text values in Excel Henriksen MS Office Support 3 23-02-2012 07:20 PM
JTextArea for input text from the user liatB Software Development 1 17-03-2010 08:37 PM
Input text value problem NetworkeR Software Development 3 28-11-2009 11:56 AM
Check multiple text box input GlassFish Software Development 2 24-11-2009 01:23 PM


All times are GMT +5.5. The time now is 05:11 AM.