jquery function call with parameters
Posted
by Kaushik Gopal
on Stack Overflow
See other posts from Stack Overflow
or by Kaushik Gopal
Published on 2010-05-24T15:08:04Z
Indexed on
2010/05/24
15:11 UTC
Read the original article
Hit count: 230
Hi a newb question:
I have a table with a bunch of buttons like so:
<tr class="hr-table-cell" >
<td>REcord 1</td>
<td>
<INPUT type="button" value="Approve" onclick="" />
<INPUT type="button" value="Reject" onclick="" />
<INPUT type="button" value="Delete" onclick="fnDeletePpAppl(222445,704);" />
</td>
</tr>
<tr class="hr-table-cell" >
<td>REcord 1</td>
<td align="center" class="hr-table-bottom-blue-border" valign="middle">
<INPUT type="button" value="Approve" onclick="" />
<INPUT type="button" value="Reject" onclick="" />
<INPUT type="button" value="Delete" onclick="fnDeletePpAppl(237760,776);" />
</td>
</tr>
I have my jquery like so:
<script type="text/javascript"> // JQUERY stuff
$(document).ready(function(){
function fnDeletePpAppl(empno, applno) {
alert('Entering here');
$("form").get(0).empno.value = empno;
$("form").get(0).applNo.value = applno;
$("form").get(0).listPageAction.value = "delete";
$("form").get(0).action.value = "pprelreqlist.do";
$("form").get(0).submit();
}
});
This doesn't seem to work.I thought this means, the function is ready only after the dom is ready. After the dom is ready and i click the button, why is not recognizing the function declaration within the .ready() function? However if i use the function directly:
<script type="text/javascript">
function fnDeletePpAppl(empno, applno) {
alert('Entering here');
$("form").get(0).empno.value = empno;
$("form").get(0).applNo.value = applno;
$("form").get(0).listPageAction.value = "delete";
$("form").get(0).action.value = "pprelreqlist.do";
$("form").get(0).submit();
}
This works. I want to get my fundamentals straight here... If i do the declaration without the .ready() , does that mean i'm using plain vanilla jscript?
If i were to do this with the document.ready - the usual jquery declaration way, what would i have to change to make it work?
I understand there are much better ways to do this like binding with buttons etc, but I want to know why this particular way doesn't seem to be working. Thanks.
Cheers. K
© Stack Overflow or respective owner