Jquery Problem

Hi… :)

I tried to move the jquery script, but there are obstacles, there is no any reaction.




<input type="submit" value="Submit" id="btn" />

<div id="test"></div>


<?php

Yii::app()->clientScript->registerScript('show', "

	$('#btn').onclick(function()

		$ajax({

	  		success:

				$('#test').html('I Love Yii');

		})

	});

");

?>



I want so that when click button then a message appears.

thank you

The problem solved.


$('#btn').click(function()

Try this:


Yii::app()->clientScript->registerScript('show', "

        $('#btn').click(function(eventObject) {

                $('#test').html('I Love Yii');

        });

");

Notice that I’ve changed $(’#btn’).onclick to $(’#btn’).click

Also, the $ajax() code you had would never have worked:

[list=1]

[*]It should be $.ajax()

[*]The jQuery $.ajax() function needs more parameters, such as the page to fetch data from. See http://api.jquery.com/jQuery.ajax/

[/list]

What are you making an AJAX request to?

In jQuery, the .click() is a shorthand for binding a click event to a callback function like so:


$('#btn').bind('click', handler);

You confused ‘.click()’ with JavaScript’s native onclick attribute.

Here’s an example I came up with for your situation: http://jsfiddle.net/alkos333/tQVjs/24/

Docs on .click() can be found here: http://api.jquery.com/click/

Thank you. I will soon learn :)