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 8386231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:52:44+00:00 2026-06-09T17:52:44+00:00

We have a program which runs either on a live environment or on a

  • 0

We have a program which runs either on a live environment or on a test environment. The only difference is that the URL on the test environment contains “/test/”. When in the test environment, some functions cause it to switch to the live environment (when the URL was hard coded!), so I’m trying to fix that.

I have created this function in JavaScript:

function GetTestMode()
{
    // If "/test/" exists in URL, keep it there (we are in test mode).
    var currentURL = document.URL;
    var sTestMode = "";
    if (currentURL.indexOf("/test/") != -1)
    {
    // test mode (according to URL)
      sTestMode = "test/";
    }
    return sTestMode;
}

This is used by the JavaScript functions and works as expected.

However, most of the UI code is in Python (creating HTML). So I want to get this JavaScript result in Python. So far I have:

import cgi
import os
import sys
import re

def DrawUI (self, short=False):
    print '<br />'
    print '<div class="box2">'
    print '<table cellspacing=0 cellpadding=0 border="0">'
    print '<tr>'

    sTestMode = "test mode = %s" % ('<a href="javascript:GetTestMode()" >')
    print 'sTestMode = ' + sTestMode + '<br />'

This causes the print statements following this code (which can even be print 'hello world') to become a link which, if I click on it, displays the correct return value from the JavaScript function in the browser.

How can I get sTestMode to contain the return value (without user interaction)?

  • 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-09T17:52:45+00:00Added an answer on June 9, 2026 at 5:52 pm

    I assume you are using mod_python.

    Here’s a hacked up example how to get the Javascript variable to the server.

    In Python, using the cgi module:

    form = cgi.FieldStorage()
    sTestMode = form.getfirst('sTestMode')
    sTestMode = cgi.escape(sTestMode)  # Avoid script injection escaping the user input
    

    In JavaScript, using JQuery (not sure if this is correct, maybe some JQuery guru can fix this if wrong):

    var filename = '/url/to/your/script';
    $.ajax({
      url: filename + '?sTestMode=' + sTestMode,
      type: 'GET'
    });
    

    If you have problem implementing the Javascript version you can make sure your Python script is correct by calling /url/to/your/script?sTestMode=something_funny in your browser.

    However, you should read up the concepts of CGI, Ajax and how mod_python works.

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

Sidebar

Related Questions

I have a php file that contains class which runs some lengthy database operations.
So I have a Linux program that runs in a while(true) loop, which waits
I have a python script that runs a program, which generates few .exe files
I have a program which runs an external, command line utility and reads the
I have a program which runs on a console and its Umlauts and other
So I have a program which runs. This is part of the code: FileName
I have an RMI program which runs fine on my computer, but when I
I have a program which does a system call: latex somefile.latex This runs ok,
I have a class called ModelView which inherits from NSOpenGLView. When my program runs
I have a program which runs a bunch of tasks as root at launch.

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.