mistypotato Posted August 11, 2008 Share Posted August 11, 2008 Hello, I have a URL that has a variable in it such as this..... http://www.anyserver.com/index.php?myvalue=1 I'm trying to pass the value of "Myvalue" to a javascript from this index.php page and I'm having no luck. Is this more of a javascript question or does it also have to do with the fact that the page itself is php? HERE IS THE JAVASCRIPT THAT I NEED TO PASS THE VALUE TO.... var xmlhttp /*@cc_on @*/ /*@if (@_jscript_version >= 5) try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP") } catch (e) { try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") } catch (E) { xmlhttp=false } } @else xmlhttp=false @end @*/ if (!xmlhttp && typeof XMLHttpRequest!='undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp=false } } function myXMLHttpRequest() { var xmlhttplocal; try { xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP") } catch (e) { try { xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP") } catch (E) { xmlhttplocal=false; } } if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') { try { var xmlhttplocal = new XMLHttpRequest(); } catch (e) { var xmlhttplocal=false; alert('couldn\'t create xmlhttp object'); } } return(xmlhttplocal); } function sndReq(vote,id_num,ip_num,units,userif,nuserid) { var theUL = document.getElementById('unit_ul'+id_num); // the UL // switch UL with a loading div theUL.innerHTML = '<div class="loading"></div>'; xmlhttp.open('get', 'rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units); xmlhttp.onreadystatechange = handleResponse; xmlhttp.send(null); } function handleResponse() { if(xmlhttp.readyState == 4){ if (xmlhttp.status == 200){ var response = xmlhttp.responseText; var update = new Array(); if(response.indexOf('|') != -1) { update = response.split('|'); changeText(update[0], update[1]); } } } } function changeText( div2show, text ) { // Detect Browser var IE = (document.all) ? 1 : 0; var DOM = 0; if (parseInt(navigator.appVersion) >=5) {DOM=1}; // Grab the content from the requested "div" and show it in the "container" if (DOM) { var viewer = document.getElementById(div2show); viewer.innerHTML = text; } else if(IE) { document.all[div2show].innerHTML = text; } } /* =============================================================== */ var ratingAction = { 'a.rater' : function(element){ element.onclick = function(){ var parameterString = this.href.replace(/.*\?(.*)/, "$1"); // onclick="sndReq('j=1&q=2&t=127.0.0.1&c=5'); var parameterTokens = parameterString.split("&"); // onclick="sndReq('j=1,q=2,t=127.0.0.1,c=5'); var parameterList = new Array(); for (j = 0; j < parameterTokens.length; j++) { var parameterName = parameterTokens[j].replace(/(.*)=.*/, "$1"); // j var parameterValue = parameterTokens[j].replace(/.*=(.*)/, "$1"); // 1 parameterList[parameterName] = parameterValue; } var theratingID = parameterList['q']; var theVote = parameterList['j']; var theuserIP = parameterList['t']; var theunits = parameterList['c']; //for testing alert('sndReq('+theVote+','+theratingID+','+theuserIP+','+theunits+','+theuser+')'); return false; sndReq(theVote,theratingID,theuserIP,theunits); return false; } } }; Behaviour.register(ratingAction); Link to comment https://forums.phpfreaks.com/topic/119164-need-help-passing-variables-in-a-url/ Share on other sites More sharing options...
dezkit Posted August 11, 2008 Share Posted August 11, 2008 is this php!?!? Link to comment https://forums.phpfreaks.com/topic/119164-need-help-passing-variables-in-a-url/#findComment-613611 Share on other sites More sharing options...
mistypotato Posted August 11, 2008 Author Share Posted August 11, 2008 Guess you missed this part of my post I'm trying to pass the value of "Myvalue" to a javascript from this index.php page and I'm having no luck. Is this more of a javascript question or does it also have to do with the fact that the page itself is php? Link to comment https://forums.phpfreaks.com/topic/119164-need-help-passing-variables-in-a-url/#findComment-613615 Share on other sites More sharing options...
monkeypaw201 Posted August 11, 2008 Share Posted August 11, 2008 Guess you missed this part of my post I'm trying to pass the value of "Myvalue" to a javascript from this index.php page and I'm having no luck. Is this more of a javascript question or does it also have to do with the fact that the page itself is php? This is javascript, not PHP, we can't help ya.. Link to comment https://forums.phpfreaks.com/topic/119164-need-help-passing-variables-in-a-url/#findComment-613616 Share on other sites More sharing options...
mistypotato Posted August 11, 2008 Author Share Posted August 11, 2008 That's what I needed to know. Thanks! The entire process I'm working with has Javascript, php and XML all involved. Noone seems to know how to handle situations like this. I guess most people only use one technology then. Link to comment https://forums.phpfreaks.com/topic/119164-need-help-passing-variables-in-a-url/#findComment-613622 Share on other sites More sharing options...
discomatt Posted August 11, 2008 Share Posted August 11, 2008 That's a silly statement. All 3 are used in conjunction all the time. Your question is extremely vague and long-winded. You haven't isolated the issue, and instead throw us a bunch of code. Seeing that PHP is server-side and JS is client side... I really don't see why you can't use var myvalue = <?php echo $_GET['myvalue']; ?> Link to comment https://forums.phpfreaks.com/topic/119164-need-help-passing-variables-in-a-url/#findComment-613626 Share on other sites More sharing options...
mistypotato Posted August 11, 2008 Author Share Posted August 11, 2008 Just because someone doesn't know and is asking for help does not make it silly. Of course I haven't isolated the issue. That's why I'm asking for help. I do not know what I'm doing and I'm asking for help for which I will be grateful. I tried the $_Get and it did not pass the variable for some reason. I can't ask about this situation without mentioning some Javascript and some XML because this is a complex scenario and all three technologies appear to be used for this at the same time. Hopefully, someone reading this will ask me something that may help me post the information needed to get help. Thanks Link to comment https://forums.phpfreaks.com/topic/119164-need-help-passing-variables-in-a-url/#findComment-613644 Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 Just because someone doesn't know and is asking for help does not make it silly. Of course I haven't isolated the issue. That's why I'm asking for help. I do not know what I'm doing and I'm asking for help for which I will be grateful. I tried the $_Get and it did not pass the variable for some reason. I can't ask about this situation without mentioning some Javascript and some XML because this is a complex scenario and all three technologies appear to be used for this at the same time. Hopefully, someone reading this will ask me something that may help me post the information needed to get help. Thanks Did you use $_Get or $_GET? PHP is case-sensitive for variables. Link to comment https://forums.phpfreaks.com/topic/119164-need-help-passing-variables-in-a-url/#findComment-613647 Share on other sites More sharing options...
revraz Posted August 11, 2008 Share Posted August 11, 2008 He didn't say your question was silly, if you re-read the thread you'll noticed it was about your comment. But anyways, $_GET should work fine. Just because someone doesn't know and is asking for help does not make it silly. I tried the $_Get and it did not pass the variable for some reason. I can't ask about this situation without mentioning some Javascript and some XML because this is a complex scenario and all three technologies appear to be used for this at the same time. Hopefully, someone reading this will ask me something that may help me post the information needed to get help. Thanks Link to comment https://forums.phpfreaks.com/topic/119164-need-help-passing-variables-in-a-url/#findComment-613653 Share on other sites More sharing options...
discomatt Posted August 11, 2008 Share Posted August 11, 2008 If you don't understand your own code, it's very difficult to get help without it being 'coded for you.' Beyond that, you've posted several functions and haven't told us where exactly you need that value. There is a difference between $_GET and $_Get. Make sure you're using the correct one. I think you're looking for more of a 'fix this for me' than a 'tell me what I'm doing wrong.' I suggest the freelance section. Link to comment https://forums.phpfreaks.com/topic/119164-need-help-passing-variables-in-a-url/#findComment-613656 Share on other sites More sharing options...
mistypotato Posted August 11, 2008 Author Share Posted August 11, 2008 revraz, I tried $_GET (and yes, I did have it lower case at one point and corrected that.) I also tried $_REQUEST. I was not able to get the function to return the variable either way using echo or print. I think my scenario is probably more complex than usual the way it handles information. Usually I can figure this stuff out but this one is really complex so Im having a hard time figuiring out exactly how it's passing information. It's all based on a star rating snippet which is php but uses Javascript and XML to help it perform its functions. I'm sending a value in the URL when I send the link to a customer so that when they vote, it records the customers customer number so I can know who was (or wasn't) satisfied and why. I'll try to go back and analyze what I "think" is going on and try not to make this a "code this for me for free" thread. thanks discomutt....you said.... 'youre looking for more of a 'fix this for me' than a 'tell me what I'm doing wrong.' Your philosophical explanation of the difference would be enlightening Link to comment https://forums.phpfreaks.com/topic/119164-need-help-passing-variables-in-a-url/#findComment-613666 Share on other sites More sharing options...
revraz Posted August 11, 2008 Share Posted August 11, 2008 Post your code on how you are trying to use the variable in your function. It's possible you are using it incorrectly and it's not available in your function. Link to comment https://forums.phpfreaks.com/topic/119164-need-help-passing-variables-in-a-url/#findComment-613669 Share on other sites More sharing options...
mistypotato Posted August 11, 2008 Author Share Posted August 11, 2008 revraz, I will do that. But I may have to post some javascript because it uses javascript in the process along with the php. If I leave out the javascript it will make no sense.....if that makes sense. thx for your replies and help. disco... thx for your help as also....Im sure you mean well Link to comment https://forums.phpfreaks.com/topic/119164-need-help-passing-variables-in-a-url/#findComment-613687 Share on other sites More sharing options...
discomatt Posted August 11, 2008 Share Posted August 11, 2008 'Tell me what I'm doing wrong' -> Has some original, self-coded work and/or shows an understanding in the 3rd party code they're using -> Has isolated the issue to a few lines of code using their own debugging methods ( var dumps, verifying input data, removing sections of code until the errors go away ) -> Has clearly defined the issue and shown some attempt at accomplishing it themselves. 'Code it for me' -> Posts 50+ lines of 3rd party code, much of which is working and does not relate to the issue itself -> Shows no significant knowledge in the languages they are posting -> Has no clear definition of the issue, as they really have no idea what their code actually does. I don't bash on newbies for no reason whatsoever. If someone shows a genuine attempt to learn a language ( crawl -> walk -> run ) I will go well out of my way to help them. I gave you a general fix... one that WILL allow you to pass a variable from the URL query string to PHP, and then output into javascript code... and you replied 'it doesn't work for some reason.' Please don't insult me. I'm here to help. [edit] Okay, lets help you First, What exactly do you want to do with this customer variable? Why does it have to interact with the javascript? What are you trying to accomplish AFTER it is available in the javascript. [/edit] Link to comment https://forums.phpfreaks.com/topic/119164-need-help-passing-variables-in-a-url/#findComment-613695 Share on other sites More sharing options...
mistypotato Posted August 11, 2008 Author Share Posted August 11, 2008 Below is the page that intitially confronts the customer. It is a php page because it has 4 php calls in it. But, it loads several javascripts as it loads. I don't know how to pass a variable in the URL for the page below TO the process. My specifc question is, when this php page calls the javascript, can I pass a variable ultimately to it from the URL even if I have to first have it read into the Javascript, then pass it to the php page? Let's say I call this page with the following URL.... http://www.Anyserver.com/index.php?CustumerNumber=125 (There are only 36 or so lines of code but less than 50 so this is a "Tell me what I'm doing wrong" post) ****************************************************************************** <?php require('_drawrating.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Untitled</title> <script type="text/javascript" language="javascript" src="js/behavior.js"></script> <script type="text/javascript" language="javascript" src="js/rating.js"></script> <link rel="stylesheet" type="text/css" href="css/default.css" /> <link rel="stylesheet" type="text/css" href="css/rating.css" /> </head> <body> <div id="container"> <Table> <TR> <TD><?php echo rating_bar('1id',5); ?></TD><TD><?php echo rating_bar('2id',5); ?></TD><TD><?php echo rating_bar('3id',5); ?></TD><TD><?php echo rating_bar('4id',5); ?></TD> </TR> </Table> <br /><br /> </body> </html> Link to comment https://forums.phpfreaks.com/topic/119164-need-help-passing-variables-in-a-url/#findComment-614051 Share on other sites More sharing options...
mistypotato Posted August 12, 2008 Author Share Posted August 12, 2008 Well, I was finally able to resolve all my issues except for one that should be rather easy.... Suppose you have a $_Get statement that reads a variable from a URL and it's there (in the URL) all is good. But what if the variable is NOT there? Currently this is causing an error. How do I "check" for the existance of this variable in the URL and if it IS NOT there, substitute a value for it the rest of the function to use? Thanks Link to comment https://forums.phpfreaks.com/topic/119164-need-help-passing-variables-in-a-url/#findComment-614194 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.