sagar mane
sagar mane

Reputation: 125

how to call a javascript function in grails 2.2.2

I am trying to call my javascript function but its not working.. Please help me out

javascript code:

<script type="text/javascript">
$(document).ready(function(){
    function confirm(){
            alert('hello world');
    }
});
</script>

textbox code:

<div class="full-filed">
            <h3>Confirm Password:</h3>
        </div>      
        <g:passwordField name="confirm" value="" class="loginTxtBox" placeholder="Password" onClick="confirm();"/>

Upvotes: 0

Views: 2765

Answers (2)

user800014
user800014

Reputation:

A simpler apprach is to attach the event in the element using JQuery. Also, javascript already have a function called confirm so I suggest you to change this name:

function confirmClick() {
  alert('click!');
}

$(function(){
  //attach a click event to the element with id 'pass'.
  $('#pass').click(function(){
    confirmClick();
  });
});

And your field should have the id:

<g:passwordField name="confirm" value="" class="loginTxtBox" placeholder="Password" id="pass" />

Upvotes: 3

Igor Artamonov
Igor Artamonov

Reputation: 35961

Your function is available only inside ready(..) function. You have to define your funciton in main context:

<script type="text/javascript">
function confirm(){
    alert('hello world');
}
</script>

Upvotes: 4

Related Questions