Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8712633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:08:59+00:00 2026-06-13T05:08:59+00:00

I purchased modalbox plugin from envato market place made in javascript i want to

  • 0

I purchased modalbox plugin from envato market place made in javascript i want to use it to implement my categories> subcategories> items. Anyhow i know JavaScript variable can be assigned a value using php however i need the opposite.

On my first step i let the user pick a category using basic links then onclick even takes them to second slide where i want to display the subcategories and items related to this category that was selected.

I tried two things:

1) setting onClick = "step2();<?php $chosen_cat = ' . $this->db->escape(trim($category)) . '?>"

Hoping i can simply assign the name of the selected category to a value and then just use $chosen_cat in step2() javascript method to display products however this breaks the javascript as there is a conflict in output;

2) I changed step2() to step2(category) and then used,
onclick=”step2(db->escape($category););” this passes the
value to the step2() method however now i would need to call <– I would need to print out
that string to php however i have no idea how to solve this
considering PHP -> JS is viable as its server to client relation but
back..

The $this->db->escape() is a http://codeigniter.com/user_guide/database/queries.html codeigniter method.

My code:

<script type="text/javascript">

        function step1() {
            modalbox.show(new Element("div").insert(
                new Element("p", { "align": "justify" }).insert(
                    <?php 
                        $categories = $items;
                        $chosen_cat = '';
                    ?>
                    <?php 
                        $i = 0;
                        foreach($categories as $category => $itemarray) {
                            $i++;
                            if($i==27){
                                echo  $this->db->escape('<a class="category" onclick="step2();<?php $chosen_cat = ' . $this->db->escape(trim($category)) . '?>" href="#">'. trim($category) . '</a>');
                            }
                            else {
                                echo $this->db->escape('<a class="category" onclick="step2();" href="#">' . trim($category) . '</a>')  . '+';
                            }
                        }
                    ?>
                )
            ), {
                "title"     : "Step 1/3",
                "width"     : 800,
                "options"   : [{
                    "label"     : "Next »",
                    "onClick"   : step2
                }]
            });
        };

        function step2() {
            alert(<?php $this->db->escape($chosen_cat); ?>);
            modalbox.show([ new Element("div").insert(
                new Element("p", { "align": "justify" }).insert(
                    "If you open a modalbox when another one is opened, it will stretch to the new " +
                    "modalbox width and height and overwrite the content.<br /\><br /\>" +
                    "You can use HTML or Prototype Elements like a DIV or a TABLE."
                )
            ),
                new Element("p", { "align": "justify" }).insert(
                    "You can have multiple contents on a single modalbox by using an array like this:<br /\><br /\>" +
                    "<pre>modalbox.show([ content1, content2, ... ], options);</pre>"
                )
            ], {
                "title"     : "Step 2/3",
                "width"     : 800,
                "options"   : [{
                    "label"     : "« Previous",
                    "onClick"   : step1
                }, {
                    "label"     : "Next »",
                    "onClick"   : step3
                }]
            }); 
        };
        function step3() {
            modalbox.show([ new Element("div").insert(
                new Element("p", { "align": "justify" }).insert(
                    "If you open a modalbox when another one is opened, it will stretch to the new " +
                    "modalbox width and height and overwrite the content.<br /\><br /\>" +
                    "You can use HTML or Prototype Elements like a DIV or a TABLE."
                )
            ),
                new Element("p", { "align": "justify" }).insert(
                    "You can have multiple contents on a single modalbox by using an array like this:<br /\><br /\>" +
                    "<pre>modalbox.show([ content1, content2, ... ], options);</pre>"
                )
            ], {
                "title"     : "Step 3/3",
                "width"     : 800,
                "hideOnPageClick": false,
                "options"   : [{
                    "label"     : "« Previous",
                    "onClick"   : step2
                }, {
                    "label"     : "Finish",
                    "isDefault" : true,
                    "onClick"   : modalbox.hide
                }]
            });
        };

    </script>

Would it be possible to set a session variable with JavaScript in the onclick event say $_SESSION[‘category’] = ‘category’ in js style and then read that session with php and unset it i dont think this would create much of a security problem as session would exist for prolly less than a second.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:09:00+00:00Added an answer on June 13, 2026 at 5:09 am

    JavaScript is never going to set a PHP variable. JavaScript runs on the client and PHP on the server. If you need to change something on the server from JS, you have to use AJAX, or send a regular HTTP request.

    Alternatively, you can have PHP generate the data that is needed at runtime on the client, usually by printing some JSON to become a JS variable

    In your example, you would need something like the following (I’ll use jQuery for simplicity)

    ... onclick="$.ajax('/category.php').done(function(data) {step2(data.category);})"
    

    Which would be much nicer if it weren’t JS within HTML

    $('#my-button').click(function(){
        $.ajax('/category.php').done(function(data) {
            step2(data.category);
        });
    });
    

    I can’t give you an AJAX tutorial, but the main thing is that you’ll make an AJAX request when you need data from the server.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently purchased the domain name simply.do. I want to use it as a
I recently purchased a virtual server from Hetzner.de, and am trying to use it
We've purchased a tool from Redgate called SQL Data Compare. I use it mainly
I just purchased Alfred App for my Mac and I want to use this
I purchased a template / theme from RocketTheme, but I can't figure out how
What exactly do certificates purchased from a CA do again (in the context of
I've recently purchased a Mac and use it primarily for C# development under VMWare
I recently purchased an authenticode certificate from globalsign and am having problems signing my
(I purchased a code signing cert from Thawte and have been going out of
Lets say that I purchased a new domain (somedomain.com) from a domain registar and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.