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,520 points
10,383 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>

Hope this helps!!

To know more about Java, join our Java course online today.

Thank you

answered Apr 14, 2020 by Niroj
• 82,840 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,840 points
3,738 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 28, 2020 in Laravel by Niroj
• 82,840 points
2,282 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,840 points
3,404 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,468 views
0 votes
1 answer
+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
31,303 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,840 points
30,232 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP