0
<script>
    alert('helllo');
    $('button.savebtn').click(function() {
        alert('testin');
        var Row1 = $(this).closest('tr').find("#mi").text();
        alert(Row1);
        var Row2 = $(this).closest('tr').find("#mn").text();
        var dataString = "Id=" + Row1 + "&Name=" + Row2;
        alert(dataString);
    });
</script>

I got the the following error from above code, is anyone able give me the reason why the error occurs??

Uncaught SyntaxError: Unexpected token < at Object.InjectedScript._evaluateOn (:875:140) at Object.InjectedScript._evaluateAndWrap (:808:34) at Object.InjectedScript.evaluate (:664:21)

8
  • You don't need <script> when adding JS in separate file. Commented Nov 18, 2015 at 13:51
  • Yup within any file with a .js extension you just write javascript, HTML is allowed in there but only as a string to be appended to other elements. Commented Nov 18, 2015 at 14:00
  • @SidneyLiebrand: Anything is allowed inside strings. Saying "HTML is allowed" makes it look like there is somwthing special about it. Commented Nov 18, 2015 at 14:15
  • I have create the different file but still the error still there: <script src="code.jquery.com/jquery-2.1.4.min.js"></script> <script src = "test.js"> </script> Commented Nov 18, 2015 at 14:15
  • @dao: Seeems like you still have HTML in a JavaScript file. That's invalid. Don't do that. Commented Nov 18, 2015 at 14:24

2 Answers 2

2

If you have your JS in a separate file you don't need to add <script> and </script>.

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

1 Comment

I have created the different file, but the error still appears on the same java scripts.
0

Here list of the full html

<!DOCTYPE HTML>
<HTML>
<HEAD> 
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="test.js"></script>
<TITLE>LIST OF GATE</TITLE></HEAD>
<BODY><H2>Data</H2>

<TABLE BORDER=1>
<TR>
<TH>ID</TH><TH>NAME</TH><TH>ACTION</TH>
<TR>
<TD id = "mi">1</TD>
<TD id = "mn" contenteditable="true">a</TD>
<TD> <button class= savebtn>Save</button> </TD>
</TR>

<TR>
<TD id = "mi">2</TD>
<TD id = "mn" contenteditable="true">b</TD>
<TD> <button class= savebtn>Save</button> </TD>
</TR>

<TR>
<TD id = "mi">3</TD>
<TD id = "mn" contenteditable="true">c</TD>
<TD> <button class= savebtn>Save</button> </TD>
</TR>
</TABLE>

</BODY></HTML>

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.