Hi !!
i faced problem with javascript. When I call function change() it applies only second element that is link2. I wanted when i click the link, the link name must appear to textfield.can anyone help??

here is code:

<html>
<body>
<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 ale = a[i].innerHTML;
			a[i].onclick =change(ale);
	}
	
	function change(object){
		var inputobj = document.getElementById("spec"); 
		inputobj.value = object;
	}
</script>
</body>
</html>

Don't use loop,the loop ends on second link,so the first one is replace with second.

then how to make it work?

You weren't really calling the function, it starts running when the page loaded. I see that you are changing the href attribute to a hash inside the loop, so i modified your code to look like this:

<html>
<body>
<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>

If u click on the links than that "innerhtml" is displayed in the textbox.

I had removed the loop since there was no need to have it, as all u want to achieve is click on the link and the value appear in the text box

Not shure using plain old JS. This works using mootools though:

$$('a').set('href', '#').addEvent('click', function() {
    $('spec').set('value', $(this).get('html'));
});

Not shure using plain old JS. This works using mootools though:

$$('a').set('href', '#').addEvent('click', function() {
    $('spec').set('value', $(this).get('html'));
});

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.