473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Passing a python variable to a javascript function?

1
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.getElementById().innerHTML 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="Python" type="text/python">
import sample
text = sample.get_string()
document.getElementById("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 10883
acoder
16,027 Expert Mod 8TB
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
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
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...
1
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...
1
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...
8
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...
1
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(" +...
2
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...
11
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...
1
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.