<form id="form1" method = "post">
Text1:<input type ="text" id="textname1"/><br>
<input type ="button" name="button2" id="button2" value="UPDATE">
</form>
<script type ="text/javascript">
$(document).ready(function() {
$("#button2").click(function(e){
alert($("#textname1").attr('value').replace('-',''));
});
$( "#textname1" ).datepicker();
$( "#textname1" ).datepicker("option", "dateFormat", 'yy-mm-dd' );
});
</script>
Suppose if i enter the date in the field 2010-07-06 .When i click the button2 i get the alert as 201007-06.How can i replace the last hyphen(-)
Change your replace function’s regular expression argument to include the
gflag, which means “global”. This will replace every occurrence rather than just the first one.