alert(this.numberOfRow);

I open this page

I write a code. I click “See Result>>”. My code is not working. Consols says “SyntaxError: syntax error tryit.asp:102”. I don’t find 102 row.
I want I write
alert(this.numberOfRow);
message box displays number of row that is in alert

How can I do this?

That’s impossible to answer without knowing what the code is now that you’ve changed it.

I want this

<script type="text/javascript">
alert(numberOfRow);// 1
//2
//3
alert(numberOfRow);//4

</script>

how can I do this?

What does your numberOfRow function look like?

numberOfRow is not a function.

I want message box displays line number

You want a relative line number for the javascript? Why?

Sorry.

I meant what does the function that numberOfRow is coming from look like.

So far I’ve seen a W3schools page that does not have that, and you saying what you want.

But I do not have any information to be able to connect the dots.

I need to see your JavaScript code.

Based on what you’ve provided so far my best guess is that

alert(numberOfRow);

will alert “undefined”

the other possibilities are that it will display nothing (if alert is turned off) or it will give a syntax error if the script is running in strict mode as the variable hasn’t been declared.

1 Like

alert(A.bul(“A.bul”));//22
line number is 22

<script id="ad">
var s = document.getElementById("ad");
alert(s.innerHTML);
var A = s.innerHTML.split("\n");
alert(A);
alert(A[0]);
alert(A[1]); // var s = document.getElementById("ad");
alert(A[2]); // alert(s.innerHTML);
alert(A[3]);  // var A =s.innerHTML.split("\n");
alert(A[4]); // alert(A)
alert(A[11]);// var t = 2;
var t = 2;
alert(s.innerHTML.indexOf("s.innerHTML.indexOf"));// 198

Array.prototype.bul=function(ara){
//alert("aaa")
for(var i=0; i<this.length;i++){
if(this[i].indexOf(ara)!=-1){
return i;
}
}
return -1
}

alert(A.bul("A.bul"));//22


</script>

The code is working in firefox 34.0.5

there is no such element in the array. since you want to find the line that contains ‘A.indexOf’ you have to make a text search in each element.

I edited my message. I tried alert(A.bul(“A.bul”));//22
It is working.
Thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.