We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

jquery on button click

Hi. I have a problem, when i am trying to create jquery on click function for my Tag::SubmitButton. I want to show simple alert message when user click on a button. Here is my view code:

<?php
use Phalcon\Tag;
?>
<?php
echo Phalcon\Tag::javascriptInclude("https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false);
echo Phalcon\Tag::javascriptInclude("javascript/jquery.js");
?>

<script type="text/javascript">

$(document).ready(function(){
    //alert($("#nesto").val());
    //atr = $(".klasa").attr("id");
    //alert("Id je: " + atr);
});

 $('#dugmic').click(function(){
        alert("Some message");

});
</script>

<h2>Basic example</h2>

<?php echo Tag::form("xml/pretraga"); ?>

 <p>
<label for="name">Title</label>
<?php $opt = array('title', 'id'=>'nesto', 'size'=>'10');
  $buttopt = array('Show', 'id'=>'dubmic','class'=>'klasa');
 ?>
<?php echo Tag::textField($opt) ?>
</p>
<p>
<?php echo Tag::SubmitButton($buttopt) ?>
</p>

</form>

I need answer as soon as possible.



98.9k

Tag::SubmitButton isn't generating the id="dubmic" ?

Your Javascript is "dugmic" and your button id is "dubmic". Also, your click binding is not in a document.ready.