Running a JavaScript function in Google App Engine directly from a separate .js file

I attempted to invoke a function from a .js file within the Google App Engine ecosystem.

Here is how the html print code looks:

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class jumpPage(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        self.response.out.write('');
        self.response.out.write('');
        self.response.out.write('<head>');
        self.response.out.write('<script type="text/javascript" src="/js/pxc11.js" >');
        self.response.out.write('</script>');
        self.response.out.write('</head>');
        self.response.out.write('<body">');
        self.response.out.write('<form name="f1">');
        self.response.out.write('  <input type="hidden" name="theStartValue" value="1"><p>');
        self.response.out.write('  <input type="button" value="-15" onClick="dummy()">');
        self.response.out.write('  <input type="button" value="+15" onClick="dummy()" ><p>');
        self.response.out.write('</form>');
        self.response.out.write('</body>');
        self.response.out.write('');
        self.response.out.write('</html>');


application = webapp.WSGIApplication(
                                     [('/tonteria', jumpPage)],
                                     debug=True)


def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

The content of the .js file is as follows:

<script language="javascript" type="text⁄javascript">
function dummy()
{
    alert("POPOPOPOPOPO");
}
<⁄script>

The app.yaml file includes a static folder that contains the .js file.

    handlers:
    - url: /js
      static_dir: js
    - url: /tonteria
      script: tonteria.py

Answer №1

.js documents house Javascript code, not HTML elements.

Answer №2

You can simplify your life by converting the document into an HTML template and then displaying it with your own custom variables. Check out an informative tutorial provided by Google.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing the reduce() function to simultaneously assign values to two variables from data input

Looking to simplify the following function using reduce(), as the operations for variables selectedEnrolled and selectedNotEnrolled are quite similar. I attempted to use map(), but since I wasn't returning anything, it led to unintended side effects ...

Using multiple onChange and value attributes in React to handle different input fields and

I am having trouble setting a maximum input value in a text field, and I can't seem to figure out how to make it work. The issue seems to be with the two onChange events and values. I'm not sure how to resolve this. function Form({ onAddStudent ...

Displaying information collected from a submission form

I am in the process of designing a cheerful birthday card and I need to transfer data from a form to the birthday card page. How can I take information from the first div (which contains the form) and display that data in the second div? <!DOCTYPE ...

Why isn't CSS showing up in preview mode on the network tab?

I have been using nextjs for server-side rendering and I am encountering an issue where my CSS class is not being applied on the preview tab, it only works on the client side. Any idea why this is happening? Here is the code snippet: https://codesandbox.io ...

Retrieve the appended element's object

I am currently facing an issue with accessing elements that are automatically added by a library in my code. In my HTML, I have the following line: <div class="bonds" id="original" style="display:block;"></div> The library appends some elemen ...

Is it possible to incorporate Javascript into Skeleton framework?

I've run into a bit of confusion while trying to navigate the world of frameworks. Specifically, I'm experimenting with Skeleton (getskeleton.com) for the first time and encountering an issue with a Javascript file. Despite referencing it in the ...

Executing functions in a pre-defined order with AngularJS: A step-by-step guide

In my AngularJS Controller, I have a receiver set up like this: // Broadcast Receiver $rootScope.$on('setPlayListEvent', function(event, playListData) { if($scope.someSoundsArePlaying === true) { $scope.stopAllS ...

Is there a way to retrieve the initial value from the second element within the JSON data?

Exploring JSON Data Collections In my JSON data, I have two collections: FailedCount and SucceededCount. { "FailedCount": [{ "FailedCount_DATE_CURRENT_CHECK": "2016-11-30 10:40:09.0", "FailedCount_DATE__CURRENT__CHECK": "10:40:09", "FailedCo ...

What is the best method to activate a JavaScript function after 1 minute of user inactivity?

I need to set up a web page where a JavaScript function is activated after 1 minute of user inactivity. The page primarily features the <form> component. What's the best way to implement this type of function? ...

Is my implementation of async await the most efficient method to handle asynchronous operations in my code?

Struggling to implement and grasp async await functions in my login example, I'm uncertain if my code is the most optimal, elegant, and clean. I especially have doubts regarding error handling, and how to best utilize const and functional programming ...

The content in an app using Ionic and Angular is being obstructed by the bottom tabs, preventing users

I am facing an issue with my Ionic and Angular app. When I place tabs at the bottom of my page, outside the ion-content, the scrolling stops working inside the ion-content and the fab button, which is located inside the ion-content, ends up covering the ta ...

The append() function works only the first time when the same code is being appended to the same div

$('.addvalue').change(function(){ val_id = this.id; count_new_btn++; count_new_inp++; if( $('#'+val_id).val() == '1'){ $('#div'+ val_id).append('<input ...

How can I achieve super subtle shading effects in three.js?

Is there a way to achieve a very soft and subtle shadow in three.js, similar to the one in this image? https://i.sstatic.net/6B6en.jpg So far, I have only been able to create something like this: https://i.sstatic.net/a3rgD.png Here are my current light ...

What is the best way to implement gravity in order to make my character jump effectively

As a beginner in the world of coding, I am currently working on creating a game. However, one major challenge I am facing is simulating gravity to make my character jump effectively. Despite trying various methods, I have encountered disappointing results. ...

Construct a string by combining the elements of a multi-dimensional array of children, organized into grouped

My task involves manipulating a complex, deeply nested array of nodes to create a specific query string structure. The desired format for the query string is as follows: (FULL_NAME="x" AND NOT(AGE="30" OR AGE="40" AND (ADDRESS ...

Crafting a Dynamic Forms Manager

Recently, I challenged myself to create a complex input form that would enable users to add an infinite number of inventory items for efficient management. Throughout this process, I have sought assistance and have significantly enhanced my script with eac ...

Sending data between PHP and JavaScript using Ajax communication

I am currently working on a PHP page that involves variables and radio buttons. When a user clicks on a radio button, it triggers a JavaScript function to calculate the price of the selected item by passing some variables. Here's how I have implemente ...

Enhance Your Browsing Experience with this Chrome Extension for Page Interactions

Recently, I came across Chrome extensions and have been intrigued by their functionality. One question that has been on my mind is: how can I programmatically trigger a button click when the extension runs? For instance, there is a button with the id &apos ...

Which approach yields better performance: setting all dom events simultaneously, or incrementally?

Is it more effective to attach event listeners permanently or only when needed? For example, consider a scenario where you have a dropdown menu in your HTML that opens when clicked. Within this menu, there is a close button that closes the menu upon click ...

React JS high-performance asynchronous computations

I'm currently facing a challenge with JavaScript while trying to perform complex calculations. I am using React together with Redux. Although making fetch or server requests using libraries like fetch or jQuery ajax works asynchronously as expected, ...