Remove only the last _ in a string using split()?

  ajax, javascript, jquery, split

trying to get table cell edit fixed i have the following code which if a string supposing has test_1_ then it removes all _ but i only want to remove the last _ and it should look like this test_1

here is the js part which needs some expert touch

 // Get edit id, field name and value
  var id = this.id;
  var split_id = id.split("_");
  var field_name = split_id[0];
  var edit_id = split_id[1];
  var value = $(this).val();

my html looks like this

<input type='text' class='txtedit' value='<?php echo date('Y-m-d h:i:s a', strtotime($row['time_in'])); ?>' id='time_in_<?php echo $row['hours']; ?>' >

now if you notice the input field id looks like id=’time_in_’ but after split i want time_in to remain remove only the last _

hope you get my point?

Thanks for your help

Source: Ask Javascript Questions

LEAVE A COMMENT