-1

I am trying to change the span with the input value what is the error on my code.

$(document).ready(function(){
  if ($('#tnx-status').val() = 'publish'){
    $("#status-p").html("Complited")
  }
   });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="tnxst" type="hidden" id="tnx-status" value="publish" />
<span id="status-p"></span>
Utpal Sarkar
  • 412
  • 5
  • 23
  • Look at your browser's debugging console. It's telling you exactly what the problem is. Or even just click "Run code snippet" in your own question. – David Sep 16 '17 at 20:27
  • I was trying but I can't fix this – Utpal Sarkar Sep 16 '17 at 20:29
  • When you were trying, what was the error message? What line of code did it refer to? What is the error message telling you and how are you trying to apply that information to your code? – David Sep 16 '17 at 20:30
  • "ReferenceError: invalid assignment left-hand side", "lineno": 16, "colno": 7 but as a new on jquery I can't understand this . – Utpal Sarkar Sep 16 '17 at 20:32
  • The problem is that you have a typo in your code. You're using `=` instead of `==` (or `===`). – David Sep 16 '17 at 20:34
  • thank you for your suggestion I got this ! – Utpal Sarkar Sep 16 '17 at 20:36

1 Answers1

1

use comparison operator === instead of assignment operator =

$(document).ready(function(){
  if ($('#tnx-status').val() === 'publish'){
    $("#status-p").html("Complited")
  }
   });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="tnxst" type="hidden" id="tnx-status" value="publish" />
<span id="status-p"></span>
Dij
  • 9,761
  • 4
  • 18
  • 35