473,667 Members | 2,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing Javascript variable to php

9 New Member
Dear Sir,

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

[PHP]<script language="JavaS cript">
function chg_subcatg(cfi eld,fieldnm)
{
// For Retrieval of current catg
var f1=document.for ms[0];
var sbox1=f1.elemen ts[cfield];
var choice=sbox1.se lectedIndex;
var c_catg = sbox1.options[choice].value;
document.forms[0].thefield.value = c_catg;

// For updation of sub category
var f=document.form s[0];
var selectBox=f.ele ments[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($sq l);
while ($row = mysql_fetch_arr ay($result))
{
?>
var extraOption=new Option('<?php echo $row['subcatg_desc'];?>','<?php echo $row['catg_id'];?>',0,0);
selectBox.optio ns[selectBox.optio ns.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 2734
code green
1,726 Recognized Expert Top Contributor
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 Recognized Expert Top Contributor
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 Recognized Expert Top Contributor
I must confess I keep hearing about Ajax but have never looked into it
Aug 16 '07 #4
nbt725
9 New Member
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 Recognized Expert Top Contributor
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
72142
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 fillForm() { // split the query string into pieces var qs = location.search.substr(location.search.indexOf("?")+1); qs = qs.split("&"); alert(qs); // qs is the variable that I need to pass into a
1
2571
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:
3
14929
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) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
2
5042
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 this particular FULL code into a MySQL field. Here's the drill: I have a timer on a PHP webpage, and i want to prevent the user from doing a
1
2409
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).
2
2167
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: newWin('/vcrc/exitvcrc.jhtml&newURL=http://www.something.net/default.asp?sponID=ETC','NowLeaving','420', '200', 'no', 'auto','no');" So, pretty much, the page I'm sending the variable to think there's two variables (newURL and sponID), but...
6
5578
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 object collection and stanrd using it it starts to fall apart. Clearly there is something about javascript's usage of passing "By ref" that i am not getting. i have had a look on the web and found some examples, but i cant see why my code does not...
5
5006
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
1957
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"
5
10282
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 may also open up new chat windows with other members (just not the same one). - Each chat page is opened with the member name as the window name. - When I log off from the web page, I would like all the chat windows to automatically close. I...
0
8366
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
8888
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
8790
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8565
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8650
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
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2779
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
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1779
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.