0

how can i specify function record (which is in item.js file)as the event handler for onclick event for "b1" button with in the following javascript

item.html-------------------

<body>

<form>
<input type = "button" id="b1" value = "click" />
</form>


<script type="text/javascript">

----code should be here------

</script>

</body>
naees
  • 21
  • 3

3 Answers3

1

You could also do:

<input type = "button" id="b1" value = "click" onclick="functionHere();" />

Therefore the Javascript is immediately applied instead of when the code is reached (as in gilly's example).

Gilly's example is also good, but this is just a different method.

Abdullah Jibaly
  • 53,220
  • 42
  • 124
  • 197
Flipper
  • 2,589
  • 3
  • 24
  • 32
  • 1
    @Abdullah , i know this method which u shown but i needed the gilly method. thanks – naees May 03 '11 at 21:54
  • @Abdullah thanks for giving me credit. But isn't javascript: necessary before the function for some browsers since not all will recognize what it is? – Flipper May 03 '11 at 21:59
  • I'm pretty sure you don't need it for event handlers but opened up a question just in case: http://stackoverflow.com/questions/5876452/when-is-javascript-needed – Abdullah Jibaly May 03 '11 at 22:27
0

Like this:

document.getElementById("b1").onclick = record;
gilly3
  • 87,962
  • 25
  • 144
  • 176
  • thank u so much for ur help. this site is really very useful in solving problems.u people doing great job – naees May 03 '11 at 21:52
0

With jQuery:

$(function() {
    $('#b1').click(record);
});
Abdullah Jibaly
  • 53,220
  • 42
  • 124
  • 197