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

  • SEARCH
  • Home
  • 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 7928911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:53:31+00:00 2026-06-03T19:53:31+00:00

Possible Duplicate: How to get JavaScript function data into a PHP variable i have

  • 0

Possible Duplicate:
How to get JavaScript function data into a PHP variable

i have a javascript variable in order.php view and i want to send that variable to a controller and then to the model to write it in to the database.

ex: var myOrderString = “something” to order.php controller.

how to do this?

  • 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-03T19:53:33+00:00Added an answer on June 3, 2026 at 7:53 pm

    To build on rayan.gigs and antyrat’s answers, below is a fix to rayan.gigs answer and how you would receive that information on the controller side:

    rayan.gigs fixed answer (modified to match controller example below):

    // your html
    <script>
        var myOrderString = "something";
    
        $.ajax({
            type: "POST",
            url: <?= site_url('OrderController/receiveJavascriptVar'); ?>
            data: {"myOrderString": myOrderString},  // fix: need to append your data to the call
            success: function (data) {
            }
        });
    </script>
    

    The jQuery AJAX docs explain the different functions and parameters available to the AJAX function and I recommend reading it if you are not familiar with jQuery’s AJAX functionality. Even if you don’t need a success callback, you may still want to implement error so that you can retry the AJAX call, log the error, or notify the user if appropriate.

    antyrat (modified to fit controller example below):

    <form action="<?= site_url('OrderController/receiveJavascriptVar'); ?>" method="POST"  id="myForm">
      <input type="hidden" name="myOrderString" id="myOrderString">
    </form>
    <script>
      var myOrderString = "something";
      document.getElementById('myOrderString').value = myOrderString;
      document.getElementById('myForm');
    </script>
    

    The controller could look like this for both of the above cases:

    <?php
        class OrderController extends CI_Controller
        {
            public function receiveJavascriptVar()
            {
                $myJSVar = $this->input->post('myOrderString');
                // push to model
            }
        }
    ?>
    

    I would recommend rayan.gigs method instead of abusing forms. However, if you are trying to submit user information or submit information along side an existing form submission, you could use antyrat’s method and just insert a hidden that you fill either on render, or via javascript.

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

Sidebar

Related Questions

Possible Duplicate: How to get javascript variable value in php I am looking for
Possible Duplicate: Get image data in Javascript? Convert an image into binary data in
Possible Duplicate: PHP get all arguments as array? Within a javascript function arguments always
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: Data transfer from JavaScript to PHP. How can i get the browser's
Possible Duplicate: Javascript/PHP can I get GPS location and send it to me? Ok
Possible Duplicate: Is there a JavaScript function that can pad a string to get
Possible Duplicate: Javascript/PHP and timezones It is possible to get the Olson timezone id
Possible Duplicate: How can I get the name of function inside a JavaScript function?
Possible Duplicate: How to profile and and get Javascript performance I have a page

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.