473,378 Members | 1,346 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,378 software developers and data experts.

Passing Javascript variable to php

9
Dear Sir,

Hello ! I want to get the javascript variable in php code in following function.

[PHP]<script language="JavaScript">
function chg_subcatg(cfield,fieldnm)
{
// For Retrieval of current catg
var f1=document.forms[0];
var sbox1=f1.elements[cfield];
var choice=sbox1.selectedIndex;
var c_catg = sbox1.options[choice].value;
document.forms[0].thefield.value = c_catg;

// For updation of sub category
var f=document.forms[0];
var selectBox=f.elements[fieldnm];
<?php
require_once "../functions_main.inc";
$cxn = Connect_to_db("../vars.inc");
// $sql = "select * from subcatg_mast where catg_id = 1";
$sql = "select * from subcatg_mast where catg_id = " . $t1;

$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
?>
var extraOption=new Option('<?php echo $row['subcatg_desc'];?>','<?php echo $row['catg_id'];?>',0,0);
selectBox.options[selectBox.options.length]=extraOption;

<?php
}
?>

}
[/PHP]

How can I pass the above java script variable c_catg to my %t1 variable to form where clause value in $sql. This variable c_catg has integer value, hence written this way to construct $sql.

Please guide.


Thanks & Regards,

Naimesh Trivedi
[EMAIL REMOVED]-by ajaxrand
Aug 16 '07 #1
5 2700
code green
1,726 Expert 1GB
Javascript is client side and php is server side so you can't directly.
You can put the javascript variable into HTML as a hidden variable or URL variable for example, then submit within a form or via a hyperlink so that PHP can extract it from the POST or GET array.
Aug 16 '07 #2
ak1dnar
1,584 Expert 1GB
Javascript is client side and php is server side so you can't directly.
You can put the javascript variable into HTML as a hidden variable or URL variable for example, then submit within a form or via a hyperlink so that PHP can extract it from the POST or GET array.
And also ajaxified solution also suited for this code green.
Aug 16 '07 #3
code green
1,726 Expert 1GB
I must confess I keep hearing about Ajax but have never looked into it
Aug 16 '07 #4
nbt725
9
Javascript is client side and php is server side so you can't directly.
You can put the javascript variable into HTML as a hidden variable or URL variable for example, then submit within a form or via a hyperlink so that PHP can extract it from the POST or GET array.
Well if you see the code in the beginning, I do store the variable in a hidden form control. But I don't know how to retrieve it as to my knowledge you need to submit a form either on link or button but not on onClick of a select control.
Can I do so or please let me know any other way to pass that stored variable to my php $sql assignment, which I checked gets displayed, if i change the type from hidden to text.

Thanks & Regards,

Naimesh Trivedi
Aug 16 '07 #5
ak1dnar
1,584 Expert 1GB
I must confess I keep hearing about Ajax but have never looked into it
Give It a try buddy. I think this is the Best Tutorial for it.
Aug 17 '07 #6

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

Similar topics

7
by: Jonas Daunoravicius | last post by:
The subject pretty much sums up what I need to do. Here is what I have so far, but still can't figure out how to get it working: <script language="javascript" type="text/javascript"> function...
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...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
2
by: RootShell | last post by:
Hello First of all i know that PHP is a server side, and JavaScript is a Client side programming language, but i need to know if there is any way i can add the variable "countDownInterval" from...
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...
2
by: brianwmunz | last post by:
Hi, I'm having a problem passing a variable through a URL because the variable is supposed to hold a URL that has a variable of its own. Here is an idea of what I'm trying to do: href="javascript:...
6
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an...
5
by: sfeher | last post by:
Hi All, I need to call a function(loaded with appendChild) for which I have the name as a string. .... var fnName = 'fn1'; var call = fnName + '('+ param +' )'; eval(call);
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...
5
by: aelred | last post by:
I have a web page where a member can open up a chat window (child window) with another member. - From there the member can also navigate to other web pages. - From other pages in the site, they...
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...
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
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,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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...

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.