473,748 Members | 9,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing a python variable to a javascript function?

1 New Member
Hi,

I'm not sure if this is a javascript problem per se, but here goes. I have an xsl document with a python function defined within a <script> block. Elsewhere in the xsl file, within a python script block, I call the python function and store the return value in a variable. I need to be able to display this returned value on the webpage that the xsl generates. I tried to do a document.write([python returned variable]) but found that document.write( ) causes firefox to hang when used within an xsl file. So instead I used document.getEle mentById().inne rHTML to display the python returned value. This works in ie7 but in firefox the output is blank. So the problem is that internet explorer is letting me pass a variable that was given a value from a python function return value and firefox is not letting me jumble the types as such.

Heres a very simplified version of the problem:

[HTML]<html>
<span id="out">This text will be replaced</span>

<script language="Pytho n" type="text/python">
import sample
text = sample.get_stri ng()
document.getEle mentById("out") .innerHTML = text
</script>
</html>
[/HTML]
import sample, imports a file called sample.py which is located in the same directory. It is just:

Expand|Select|Wrap|Line Numbers
  1. #sample.py
  2. def get_string():
  3.     return "ABCD"
  4.  
I want the text in <span id="out"> to be replaced by the "text" variable in the script block. This does not work in firefox however it does work in ie. I'm looking for a solution that works in both browsers obviously. This example is embedded in an html block but in the full version, the html is embedded in an xsl stylesheet.

I'm really stuck here and the only other option I can think of is to rewrite the python function in javascript but this would be my last resort as the real python function is pretty complex.

Is there any way to pass the python variable to the javascript function call?

Thanks in advance
Feb 22 '08 #1
2 10916
acoder
16,027 Recognized Expert Moderator MVP
I don't know if this will help, but the span should be within body tags.

Not really dabbled with Python, but, generally speaking, when you need to pass a server-side function to JavaScript, you use the server-side language to generate the JavaScript. I'm not sure if Python fits into this.
Feb 25 '08 #2
Irfan Younas
1 New Member
USING JSON/simplejson u can dump the python data structure into JSON data structure, which can be accessed in javascript.
Jul 30 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2578
by: Patrice | last post by:
Hi, I'm trying to use a javascript function passing a vb variable. I don't understand why it doesn't work. Can someone help me? Thanks in advance. Here is my javascript function used to show a text:
1
2423
by: cirillo_curiosone | last post by:
Hi, i'm new to javascript. I started studing it on the web few weeks ago, but still haven't been able to solve one big problem: HOT TO PASS VALUES FROM A SCRIPT VARIABLE TO A CHILD HTML GENERATED BY FUNCTION. Here'e the point: I'm writing a simple website for showing my photographs. It has a central page with many links (as many as galleries are).
1
4334
by: ms_chika | last post by:
Please help! I just want to know how can i pass the return value of a javascript function to a xsl variable. I have an xsl file and from that file i will call a javascript function then the result will be stored in to the <xsl:variable> how will i do that? Or is it really possible to do that or is there other way of doing it? Your help will be very much appreciated.
8
1478
by: nescio | last post by:
hello, i have got a javascript that opens a new window. when i call the javascript function i want to ad a variable. what you see on the pop up depends on the variable. but the variable in the functions does not work. on the pop up page it has the value: $nummer = $_GET echo 'nummer: ' . $nummer
1
1862
by: alf | last post by:
Hi, how can I pass a value from ASP.NET to a javascript function in the client-side ?? my problem is appening the ' at beginin and end of the argument: href=<%# "javascript:myFunction(" + HttpUtility.UrlEncode(DataBinder.Eval(Container.DataItem,"id").ToString()) + ")" %> the previous line will generate: href=javascrip:myFunction(25)
2
1967
satterfieldben
by: satterfieldben | last post by:
I have a newbie question about passing variables between functions. I am wanting to use a drop down box to select a value. Then base on which was selected, it would create a variable and I would call that variable in another Java script. Sample script <SCRIPT LANGUAGE="JavaScript"> function GetSelectedItem() { len = document.formname.selectname.length i = 0 chosen = "none"
11
2864
by: haijdp | last post by:
Hi , the below statement is in a java program,in that xmlforDisplay is the java variable whose value i have to pass to the javascript function as follows, with the below code,I am getting the syntax error.Please help me... out.println("<input type='button' value='Transform' onclick='javascript:eventHandlerFunction(document. formlob.lobselection.value,\''"+xmlforDisplay+"'\',null)'></td></tr></table><br><br>");
1
1509
by: rag84dec | last post by:
Hi, i tried the following to use a string from asp code in javascript but it didnt work....please tell me how to pass a string to a javascript <script language="JavaScript"> function ChangeAll(f) { alert(f);
5
1942
by: neogazz | last post by:
I am trying to a pass "text sentence" from a JavaScript function into my XHTML program is this possible?? 3134 Please see attached attached JavaScript coding. The reason why I am trying to pass text from JavaScript to my XHTML program is, because depending on whether or not a certain input field is filled out or not I want certain text to be displayed within my XHTML page... Regards Gary Wilson
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.