Jquery cannot get value from textbox in joomla
jQuery cannot get value from textbox in Joomla, 开发者_运维问答I'm using the script as the follows:
<?php JHTML::_('behavior.jquery'); ?>
<script>
jQuery.noConflict();
jQuery(function(){
jQuery("#register").click(function(){
alert($("#txtusername").val());
});
});
</script>
<form name="frm1" id="frm1" method="get">
<table border="0" style="width:100%;">
<tr>
<th colspan="2" align="center">Register</th>
</tr>
<tr>
<td align="right">Username:</td>
<td><input type="text" name="txtusername" id="txtusername"/></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><input type="text" name="txtpassword" id="txtpassword"/></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr><td> </td><td><input type="button" id="register" value="register"/></td></tr>
<tr>
<td colspan="2">
</td>
</tr>
</table>
</form>
While you using jQuery.noConflict()
. you can't use $
you are alerting value using $
alert($("#txtusername").val());
change this as
alert(jQuery("#txtusername").val());
have a look at this working example
精彩评论