-1

I'm update value via javascript class. How to check the current value is set or not.

My code is below,

<script>
    $(document).ready(function() {
        $(".sampleClass").click(function(){
            var sampleValue = $(this).val();
            var samplePrice = $(".samplePriceValue").val();
            .....
        });
    });
</script>
Ivar
  • 6,138
  • 12
  • 49
  • 61
  • 1
    Please explain what you are asking. – Pupil Apr 23 '19 at 11:19
  • 1
    Your browser has a Debugger (Normally F12 to launch it) Just set a break point on the first `var ....` line then step throught the code and look at the values – RiggsFolly Apr 23 '19 at 11:19
  • 1
    [This answer](https://stackoverflow.com/questions/4539253/what-is-console-log) regarding `console.log` might help you. It may also help if you find and read some tutorials on how to use your browser's developer tools to help you debug your code and inspect variables. – Geekfish Apr 23 '19 at 11:25

1 Answers1

2

In javascript we can use console.log() to check the current value. The value is displayed in console.

For example use this below line.

<script>
    $(document).ready(function() {
        $(".sampleClass").click(function(){
            var sampleValue = $(this).val();
            console.log(sampleValue);
            var samplePrice = $(".samplePriceValue").val();
            console.log(samplePrice);
            .....
        });
    });
</script>

Run your application.

And press F12 the console window will be opened in your browser. In console you can view the values.

The sample output

sampleValue
samplePrice
  • Good answer, but would be made better by detailing how you get to the console, as not everybody knows about the developer tools built into browsers – freefaller Apr 23 '19 at 11:22