Reputation: 125
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
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
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