0

There is a left side menu on the site. It is required when you hover the mouse cursor over a menu item - a product category (hyperlink) or by clicking on it, write the text of this menu item (the text of this hyperlink) to a variable. Depending on the value of this variable, the right side menu is displayed, i.e. depending on the product category, a list of product characteristics is displayed (the right side menu is a list of characteristics), i.e. html or php code is located depending on these variables. Mouse click and mouse over is javascript. How can I access the javascript variable from 1.html and 2.php code?

Goodscharacteristics

  • 1
    Does this answer your question? [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – luk2302 Mar 12 '21 at 08:22
  • how much data is in there anyway?, just preload the values that you need and just manipulate the show and hide animation via css and / or javascript – Kevin Mar 12 '21 at 08:30
  • to allow PHP to work with Javascript variables requires communication between the browser and the server in the form of an HTTP request - most commonly done using AJAX – Professor Abronsius Mar 12 '21 at 08:31

1 Answers1

0

Its imposible. Rename your index.html file to index.php (You can write html code inside .php file and "inject" php variables into html code).

Exmaple:

<span><?= $my_variable?></span>

or:

<a href="<?= $my_link?>">Go</a>

or even you can display your html block depending on some condition:

<?php if ($my_condition): ?>
    <div class="card">
        <div class="card__title">Guide #1</div>
        <div class="card__body">
            <div class="card__text">Something</div>
            <button class="card__btn">Click me!</button>
        </div>
    </div> 
<?php endif ?>

So this allow you display any information you want, just cut your html code with php tags

Other example with complex conditional algorithm

<?php if ($is_auth): ?>
    <a class="fw-bold nav-link me-2 text-light" href="account.php">User</a>
    <a class="fw-bold nav-link text-light" href="login.php?d=logout&uid=<?= $user_id?>">Log Out</a>
<?php else: ?>
    <a class="fw-bold nav-link me-2 text-light" href="login.php">Log in</a>
    <a class="fw-bold nav-link text-light" href="registr.php">Registr</a>
<?php endif ?>

There is another solution. Just use Ajax requests and render html code using js

daglue
  • 1