Hi all,
How to convert a php variable into the javascript variable. I need this because i want to display the content of php variable in the textbox of html field.
With regards
10 16791
Heya, Kumuda.
You can display a PHP variable in a textbox like this: -
<textbox><?php echo $variable; ?></textbox>
-
If you absolutely need to transport the PHP variable to Javascript, simply create JavaScript code to generate the variable: -
echo '
-
<script type="text/javascript">
-
// <![CDATA[
-
var myVar = "' . $variable . '";
-
// ]]>
-
</script>';
-
Hi all,
How to convert a php variable into the javascript variable. I need this because i want to display the content of php variable in the textbox of html field.
With regards
No need to go with java script....try this -
<?php
-
$i='value';
-
echo '<input type="text" value ='.$i.'>'
-
?>
AMT, please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Hi pbmods,
I tried the code -
<script language="javascript">
-
/ <![CDATA[
-
-
var myVar = "' . $Name . '";
-
alert(myVar);
-
-
// ]]>
-
</script>
-
But this is not working, it is just displaying the '.$Name.' but the contents of variable. Please help me.
With regards
Atli 5,058
Expert 4TB
Hi.
PHP and JavaScript do not work together. PHP is executed Server-side before your JavaScript code is executed on the client's browser.
You need to use PHP to generate the JavaScript code.
Like this: -
<script language="javascript">
-
/ <![CDATA[
-
-
var myVar = "<?php echo $Name; ?>";
-
alert(myVar);
-
-
// ]]>
-
</script>
-
Thank you Atli
It is working.
Hi all,
I have one more issue.
I want to add one option dynamically to dropdown box i.e. it will get the value from another page on clicking a link and it should add that value to existing list of dropdown box values.
I have used the following code where 'SelectSP' is the name of the dropdown box -
<script language="javascript">
-
-
var Name = "<?php echo $name; ?>";
-
document.getElementById('SelectSP').value=Name;
-
-
</script>
Hi all,
I have one more issue.
I want to add one option dynamically to dropdown box i.e. it will get the value from another page on clicking a link and it should add that value to existing list of dropdown box values.
I have used the following code where 'SelectSP' is the name of the dropdown box - <script language="javascript">
-
-
var Name = "<?php echo $name; ?>";
-
document.getElementById('SelectSP').value=Name;
-
-
</script>
An dhere rhe html code - <tr>
-
<td align="right" >
-
<label id="lblSelctSP">Please select the service provider :
-
</td>
-
<td align="left">
-
<select name="SelectSP">
-
<option value="" selected>[Select]
-
<option value="SP1">Sp1
-
<option value="SP2">SP2
-
<option value="SP3">Sp3
-
</select>
-
</td>
-
</tr>
kumuda v,
You have posted more than 10 posts to the Forum so far, But you have missed the CODE tags while posting source codes. Please use them in the future.Thanks.
Atli 5,058
Expert 4TB
Hi all,
I have one more issue.
I want to add one option dynamically to dropdown box i.e. it will get the value from another page on clicking a link and it should add that value to existing list of dropdown box values.
...
You can use PHP to dynamically build your dropdown box.
Consider this code: -
<select name="mySelect">
-
<?php
-
for($i = 0; $i < 3; $i++) {
-
echo "\n\t<option value=\"$i\">Item #$i</option>";
-
}
-
?>
-
</select>
-
Which would output something like this -
<select name="mySelect">
-
<option value="0">Item #0</option>
-
<option value="1">Item #1</option>
-
<option value="2">Item #2</option>
-
</select>
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Stefano |
last post by:
Posted: Fri Jan 23, 2004 3:59 pm Post subject: Variable Javascript
--------------------------------------------------------------------------------
Hi all,
i have a problem with...
|
by: Matt |
last post by:
If I assign Java variable a to javascript variable x, it is
fine.
<%
int a = 10;
%>
var x = <%= a %>;
alert(x);
But if I do the other way around, then it has 500 error. any ideas??
|
by: tnhoe |
last post by:
Hi,
if I have both javascript and aspscript,
how to get/retrieve the variable value in javascript into asp variable ?
regards
hoe
|
by: mbasil7 |
last post by:
Hi at all!
I want to use a javascript variable in php. The reason is that i want
to know the client's screen resolution.
Keep in mind that i am not a javascript programmer but php.
Here is...
|
by: stahl.karl |
last post by:
I have a CGI/Perl program that returns a string output. Is it possible
to get this into a Javascript variable, where the name of the variable
is defined in the Javascript and not in the Perl code?...
|
by: pleaseexplaintome |
last post by:
Hi I have the following perl/cgi script snippet. The goal of this
script is to pass a javascript variable to perl where it can be re-used
later. Any help is appreciated, Thanks
...
|
by: sumanbangladesh |
last post by:
hi
I am new both in php and javascript. I have a javascript varialbe. But I need a php variable with the same contents.How can I do it.
thanks in advance
|
by: Arsale |
last post by:
I am trying to pass a javascript variable to php on javascript generated page, but on the new page I got only "Array". Where did I go wrong?
On first page, i've got image map with areas....
|
by: shinu bhaskar |
last post by:
how to assign a JavaScript variable to a jsp variable in a single page
Ex :
<script type="text/javascript">
var MM=Calculate_Form('<%=DATE_INSTALL%>','<%=TILLDATE%>');
alert(MM);
</script>...
|
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...
|
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...
|
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: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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...
| |