1

I need to use Substring in Javascript. But despite my searches, i have an error : substr seems to be unknown...

function confirm_ticket(idAgir,TempsEstime) {

    var str = TempsEstime;
    var strConcatenate = TempsEstime.substr(0, 2) + ":" + TempsEstime.substr(2, 2);

    alert("confirmer le temps de maintenance de " + strConcatenate + " min pour le ticket " + idAgir);
}

Is there anything wrong in this ? thanks in advance

2
  • what is the type of TempsEstime? Commented Mar 22, 2012 at 15:03
  • What is related with c#? Commented Mar 22, 2012 at 15:03

4 Answers 4

3

The substr and substring methods in JavaScript are bound to the String object, so they only work on string types. Use the typeof keyword to determine what time you are applying the methods to.

substr takes two arguments: 1) which index to start, 2) how many characters

substring takes two arguments: 1)which index to start, 2) which index to end

EDIT: The white space formatting was jumbled.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 Why the downvote? its the only answer to understand .substr is perfectly fine and that the only cause of the error is a type error
0

I think you're looking for substring()

http://www.w3schools.com/jsref/jsref_substring.asp

function confirm_ticket(idAgir,TempsEstime) {

    var str = TempsEstime;
    var strConcatenate = TempsEstime.substring(0, 2) + ":" + TempsEstime.substring(2, 2);

    alert("confirmer le temps de maintenance de " + strConcatenate + " min pour le ticket " + idAgir);
}

1 Comment

0

Try using .substring() and see if that works.

Another thing to notice, make sure the type of 'TempsEstime' is a string.

Comments

0

you have to use substring() method:

<script type="text/javascript">

var str="Hello world!";
 document.write(str.substring(3)+"<br />");
 document.write(str.substring(3,7));

</script>

FROM: JavaScript substring() Method

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.