Error Uncaught SyntaxError Identifier Common has already been declared after making javascript class object in console

0 votes
class Common
{
   constructor(){
    this.URL=location.protocol + '//' + location.host+'';
   }

    showOk(){
    console.log('ok');
    }

}
const commn=new Common();

Here is my html codes that I've tried to call the showOk() function.

<button type="button" class="btn btn-01 btn-checkout-login ml-auto w-100 text-center" onclick="return commn.showOk();" ;="">Continue Checkout</button>

<button type="button" class="btn btn-01 btn-checkout-login ml-auto w-100 text-center" onclick="commn.showOk();" ;="">Continue Checkout</button>
Apr 14, 2020 in Laravel by kartik
• 37,490 points
4,786 views

1 answer to this question.

0 votes

Hello,

You can write like this, you need know, class's instance's function is different with normal function.

<button onclick="handleClick();">click</button>

<script >

class Common {
   constructor(){
    this.URL=location.protocol + '//' + location.host+'';
   }

    showOk(){
     console.log('ok');
    }

}
const common = new Common();

function handleClick() {
  common.showOk();
}
</script>
answered Apr 14, 2020 by Niroj
• 82,560 points

Related Questions In Laravel

0 votes
1 answer

Error:Object of class Illuminate\Database\MySqlConnection could not be converted to string

Hello @kartik, The use keyword is what you need: $id = ...READ MORE

answered Sep 24, 2020 in Laravel by Niroj
• 82,560 points
290 views
0 votes
1 answer

Error: Class 'TestCase' not found in D:\xampp\htdocs\laravel\app\tests\ExampleTest.php on line 3 ,

Hello @kartik, Run following command in your project's ...READ MORE

answered Sep 27, 2020 in Laravel by Niroj
• 82,560 points
235 views
0 votes
1 answer

Error: Class 'SoapClient' not found in /home/user/mysite.com/path/to/file.php on line 16

Hello @kartik, find this line in php.ini : ;extension=soap then ...READ MORE

answered Oct 29, 2020 in Laravel by Niroj
• 82,560 points
100 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,842 views
0 votes
0 answers
+3 votes
2 answers

Error - 419 Sorry, your session has expired.Post request in Laravel?

Sometimes the cache can also lead to ...READ MORE

answered Aug 28, 2020 in Laravel by Ishita
• 150 points
13,914 views
+1 vote
1 answer

Error:Class '\App\User' not found in Laravel when changing the namespace in Laravel?

Hello @kartik Go to config/auth.php and change App\User:class ...READ MORE

answered Apr 3, 2020 in Laravel by Niroj
• 82,560 points
9,969 views