Reputation: 2071
I have several text boxes with class name 'check'. It already has '12/12/2001 00:00:00' string. I want to remove the '00:00:00' part from every text boxes. How do I do this from jquery?
Upvotes: 0
Views: 2559
Reputation: 77778
This should do the trick
$('input.check').each( function() {
var elem = $(this);
var value = elem.val().split(' ')[0];
elem.val(value);
});
Upvotes: 1
Reputation: 68
$('.check').each(function(i){
var checkValue= $(this).val();
checkValue.replace('00:00:00','');
$(this).val(checkValue);
});
Try this code
Upvotes: -1
Reputation: 94439
Jquery/Javascript
var val = $(".check").val();
$(".check").val(val.substring(1, val.indexOf("00:00:00")-1));
HTML
<input class="check" value="12/12/2001 00:00:00"/>
Example: http://jsfiddle.net/VkcFm/
Upvotes: 0
Reputation: 176896
Dont have idea about your server side code, you might do like this
$(document).ready(function () {
$('.check').each(function () {
$(this).val($(this).val.replace(" 00:00:00",""));
}) });
Upvotes: 0
Reputation: 1074238
Just get the value and truncate it at the first space.
$("input.check").each(function() {
var index = this.value.indexOf(" ");
if (index >= 0) {
this.value = this.value.substring(0, index);
}
});
You can do it with a shorter bit of code using split
, but it works harder:
$("input.check").each(function() {
this.value = this.value.split(' ')[0];
});
Upvotes: 2