Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I am new to Javascript world. In my project codings i have 5 Javascript functions and 5 href's. whenever i click the href, then its respective Javascript function should be called(which will invoke the respective method from code behind page). But when ever i click any href link, its calling the last Javascript function(i.e function fifth() here).

I have mentioned my codings below :
HTML
<script type="text/javascript">
            function first() {
                functionaCall = '<%= fill("first") %>';
            }
            function second() {
                functionaCall = '<%= fill("second") %>';
            }function third() {
                functionaCall = '<%= fill("third") %>';
            }
            function fourth() {
                functionaCall = '<%= fill("fourth") %>';
            }
           function fifth() {
                functionaCall = '<%= fill("fifth") %>';
            }
</script>
.
.
.
.
.
<ul>
		<li ><a href="#" id="first"  önclick="first();" >1</a></li>
		<li><a href="#" id="second" önclick="second();">2</a></li>
		<li><a href="#" id="third"  önclick="third();">3</a></li>
		<li><a href="#" id="fourth" önclick="fourth();">4</a></li>
		<li><a href="#" id="fifth" önclick="fifth();">5</a></li>
</ul>


Please let me know how to call the Javascript functions based on the href clicked respectively.
(i.e when href-1 is clicked, then it should call function first()...similarly for all the href click's)


Thanks in Advance :)
Have a great day all :)
Posted
Updated 21-Feb-14 4:01am
v5
Comments
Krunal Rohit 20-Feb-14 11:22am    
IPL :)
-KR

1 solution

Why you don't put Id to your href?
<ul><li><a id="Five" href="#" önclick="fifth();">5</a></li></ul>
 
Share this answer
 
Comments
SRK90 20-Feb-14 11:50am    
yupp mate , Added now :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900