473,325 Members | 2,342 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,325 software developers and data experts.

Variable conversion PHP to Javascript.

Hi;

I'm a beginner and I'm getting a big headache figuring how to convert php variables into Javascript variables.
I want to use the content of $theName as the value for an input tag. $_SESSION['$Sess_Name'] is loaded with the right data, I verified it. But my function InitField returns always the word NULL.
Why is that? Where is the problem?

Thanks

Expand|Select|Wrap|Line Numbers
  1. function InitField() {
  2.     <?php
  3.     $theName = $_SESSION['$Sess_Name'];
  4.     ?>
  5.     var tempoVar =     "<?php echo json_encode($theName); ?>";
  6.     var myInput = document.getElementById('theName');
  7.     myInput.value = tempoVar;
  8. }
  9.  
Jan 23 '15 #1

✓ answered by Dormilich

But my function InitField returns always the word NULL.
your function doesn’t have a return value.

PS. it’s quite odd to name an array key with a $, which usually indicates a variable. may lead to confusion …

1 1256
Dormilich
8,658 Expert Mod 8TB
But my function InitField returns always the word NULL.
your function doesn’t have a return value.

PS. it’s quite odd to name an array key with a $, which usually indicates a variable. may lead to confusion …
Jan 26 '15 #2

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

Similar topics

1
by: Florin | last post by:
Hi, How to return a variable from javaScript to the visual basic? The script is loaded into the webbrowser control as a html page. THX
5
by: seans | last post by:
Hi, Is there a way to create a static variable in Javascript? I want to use a recursive function to traverse a DOM tree and examine each node. If the node is a text object I would like to save...
2
by: Augusto Cesar | last post by:
Hello people. How can I Pass ASP Array variable to Javascript; I´m to trying this: <script language="JavaScript"> var x = new Array(10);
5
by: Jade | last post by:
I saw some web page saying I could do it this way in javascript: var iNumber = <%#publicvarname publicpropertyname %> but it doesn't seem to work. I have this piece of code here in...
0
by: jason.gyetko | last post by:
How do I set a Profile variable in JavaScript. I'm calling JavaScript function for OnKeypress and have to assign the variable at that point. Thanks for the help.
2
by: swapna | last post by:
Hi, I have one doubt in my project i.e i should keep the value of java variable to javascript variable. thanks in advance.
1
by: samiul | last post by:
HI, Here is a question that is , is it ever possible to pass data from PHP variable to Javascript variable? if yes then please let me know and if not why? I think it is possible... Samiul haque
5
by: gubbachchi | last post by:
Hi all, How to pass the php date variable to javascript function. Here is the code I have tried out, but this is not recovering the date correctly in the javascript function <html> <script...
7
by: vinodsk101 | last post by:
Hi all, I have one doubt, can we pass a variable from javascript to servlet??? In Brief, i am getting some values in javascript through jsp and the same values i want in servlet. Ya i know i...
1
by: sweetneel | last post by:
hi all, thax in advance. i have a variable in my aspx page , whose value is given by sessionn variable of this page, now i want to access this variable in javascript , is it possible.then how. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.