The same with jQuery looks like this:

<input type="text" id="myid" value="World" />
<script type="text/javascript">
$(function() { //document.ready

  $("#myid").click(function() {
    alert( "Hello " + $(this).val() );
  }

});
</script>

You don't have to pass anything to the function since the 'this' context
variable is equal to the element to which the event was bound. If you want
to pass some other value to the function, there are a couple of ways to do
that, but which one to pick would really depend on the what/why. In other
words, it's hard to say without a more real scenario.

- Richard

Richard D. Worth
http://rdworth.org/

On Thu, Sep 25, 2008 at 11:22 PM, JQueryProgrammer <[EMAIL PROTECTED]>wrote:

>
> 1. I have some simple queries with regards to function calling. In
> plain javascript if I want to call a javascript function from my HTMl
> tag i do it like:
> <input type="text" id="myid" onclick="javascript:sayHello(this.id);"
> value="World" />
> Now my javascript function would be defined as
> function sayHello(id) {
>    alert("Hello " + id.value);
> }
>
> Now I want to use JQuery to do such kind of programming wherein some
> value (not necessary something from the attribute) is passed t o the
> function and processing is done. Can anyone please guide me as to how
> can it be acomplished.
>

Reply via email to