JavaScript - Get A Variable From A Remote Page And Define As Variable (read More Here)
Hi,
I have a programing problem that have been around for ages. I have search on google using several expressions and words and after hours of digging i'm still unable to do it. I would like to get a value from a HTML page hosted remotely with an inconstant value. Then define this value and name as a javascript variable and apply or show in my page. Thanks for all the help P.S. Is there any way to make a domain lookup in javascript? I mean a user enters a domain and the script converts to an ip and shows to the user. If not thanks, probably it can only be done in the server side... Similar TutorialsHi everyone! I am building a simple web application in which the user inputs some html code in a <textarea> and the corresponding result (output of the code) is shown! The problem I am facing is that suppose the user enters some code and wishes to wrap it inside specific tags (e.g. <script></script>) then she just selects the corresponding code and clicks a predefined button and the selected code gets wrapped inside those tags! Now, what I am thinking right now is that when the user selects some code and clicks the button the selected text goes inside a variable (e.g. old_variable) and a new variable (new_variable = "<script>" + old_variable + "</script>") is returned! But I was just wondering how to send the selected code in the variable i.e. old_variable using JavaScript? Any help/hint/suggestion/advice would be highly valuable for me! Thanks! Hi, Here's a sample form: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Sample form</title> <script type="text/javascript"> function displayResult() { alert(document.myForm.myInput.value); } function getFocus() { if (document.myForm.myInput.value == document.myForm.myInput.defaultValue) { document.myForm.myInput.value = ""; } } function loseFocus() { if (document.myForm.myInput.value == "") { document.myForm.myInput.value = document.myForm.myInput.defaultValue; } } </script> </head> <body> <form name="myForm" method="get" onsubmit="return false;" action=""> <input name="myInput" value="Hello world!" onfocus="getFocus();" onblur="loseFocus();"><br> <input type="button" onclick="displayResult();" value="Display input value"> </form> </body> </html> It works with no problem, but the following doesn't: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Sample form</title> <script type="text/javascript"> var x = document.myForm.myInput; function displayResult() { alert(x.value); } function getFocus() { if (x.value == x.defaultValue) { x.value = ""; } } function loseFocus() { if (x.value == "") { x.value = x.defaultValue; } } </script> </head> <body> <form name="myForm" method="get" onsubmit="return false;" action=""> <input name="myInput" value="Hello world!" onfocus="getFocus();" onblur="loseFocus();"><br> <input type="button" onclick="displayResult();" value="Display input value"> </form> </body> </html> What's wrong with it and how can I define a global variable to be used by all the functions? Many thanks in advance! Mike This little snippet tells me that using "read" as the saved cookie doesn't work. But using "listen" "speak" "write" etc. works OK. Code: else if (lessonnum == "reading"){ // oddly, "read" as cookie value fails. Why? so.addVariable('file','/images/101online/Introduction/readsubtest/audioRead.mp3'); } I had to change it to "reading". Is this normal? Is there a place where I can find all the reserved values that won't work as cookie drops? hi , i am trying to pass a javascript variable into URL ..but not getting the value.. var newID = 2; row.insertCell(6).innerHTML = "<a href=Update_Gate.cfm?GateIdVar=newID>Edit Gate</a>"; i am getting "newID" in Update_Gate.cfm page ... i want to pass this javascript variable in url and read it on the other page as form field value any help !! Hello I have a php page in which I declared a js variable... right at the top of the page... <script type="text/javascript"> var tester = 0; </script> Later in the page I test this variable... <script type="text/javascript"> if (tester==1){ do some stuff!! } </script> But I keep getting an error variable _tester undefined Am I missing something obvious... I am new to js... but this seems really straightforward Hi! I have a javascript in the head of the document which has a variable named "ref2" ... ref2 is already working as I can see its value working in another function. I need to send this variable as the value of a hidden field in the form which is in the body of the document. This is my JavaScript Code: Code: function WriteContactFormStatement1 () { var ContactFormValue = ref2; document.write('<input type="hidden" name="UReferrersName" value="' + ContactFormValue + '" />'); } var WriteContactFormStatement = WriteContactFormStatement1 (); And at the end of my form, before the submit button, I have the following code: Code: <!-- START -- Javascript to print the statement for UReferrersName --> <script language="JavaScript" type="text/JavaScript"> //WriteContactFormStatement(); document.write (WriteContactFormStatement); </script> <!-- End -- Javascript to print the statement for UReferrersName --> When I execute the form, it doesn't work the way it should, plus, gives me a word "undefined" next to the "Submit" button ..... Please help !... - Xeirus. I don't know how I should do ? Quote: <html> <head> <script type="text/javascript"> function add(a,b){ y=a+b return y } var aaa = add(one,two) //one needs to get somehow get the value of yil, in this case 10 var one = function reas(){i=10;if(i<10){yil = 15}; else{yil = 10; yil = one;}; var two = 20; document.write(y) </script> </head> </html> also why doesn't this work? Quote: <html> <head> <script type="text/javascript"> function adder(a,b){ var k=a+b; return k } var hes=adder(5,kol); kol=40; alert(hes); </script> </head> </html> you cannot have variables in callback functions? Hello. I am very new at using javascript and jquery. Right now Im working on a website, and it has a hierarchical menu in the right and im also doing some content loading in a div, all that with javascript. My problem is that when they click on a link, I need to pass a variable "id" through the link. I dont want to pass it in the url, but I want to pass it in another way, for every link the id is going to be different. How can I pass a variable to another page and how can I retrieve it in that page so I can use it for the content loading? Thanks! Hello I have a piece of javascrip that refreshes the page: ---------- Code: <script type="text/javascript"> <!-- Begin function reFresh() { location.reload(true) } /* Set the number below to the amount of delay, in milliseconds, you want between page reloads: 1 minute = 60000 milliseconds. 2 minutes = 120000 milliseconds 5 minutes = 300000 milliseconds*/ window.setInterval("reFresh()",20000); // End --> </script> -------- I am new to javascript and wanted to use an html options menu in order to be able to choose the refresh interval: Code: <SELECT NAME="refreshtime"> <OPTION VALUE="60000">1 min</option> <OPTION VALUE="120000">2 min</option> <OPTION VALUE="180000">3 min</option> <OPTION VALUE="240000">4 min</option> </SELECT> I know that I have to pass a variable to the function. I have tried several variations but none have worked. I have mostly received a "done with errors" warning. Any help would be appreciated. Thanks Zam Hello everybody I have a problem with Java Script damned I want to add the values of several variables in one variable and then use this variable, which contains the values of variables You can see the following example HTML Code PHP Code: <input type="text" name="txt1" /> <br/>age <input type="text" name="txt2" /> <br/><br/> <input type="button" name="submits" value="send"/> Javascript Code PHP Code: field = document.getElementsByName('txt1')[0]; field2 = document.getElementsByName('txt2')[0]; submit = document.getElementsByName('submits')[0]; data = 'data=' + field.value + '&data2=' + field2.value + '&submits=' + submit.value; document.getElementsByName('submits')[0].onclick = function(){ alert(data); } After executing this code I find that the variables are not displayed values As in the following picture I want to know what the cause of this problem ? If I manually write out "2/22/2012 4:00 PM" in TargetDate, I get the correct result for what I want to do (a countdown). But I want the countdown to always be the current day at 4pm. So I tried the code below thats commented, but it is not working. New to javascript, still reading the books, just hoping for some guidance on this. Code: Next Update: <script language="JavaScript"> var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() TargetDate = "2/22/2012 4:00 PM"; //TargetDate = "document.write(month + "/" + day + "/" + year) + 4:00PM"; BackColor = "white"; ForeColor = "red"; CountActive = true; CountStepper = -1; LeadingZero = true; DisplayFormat = "%%H%% H, %%M%% M, %%S%% S"; FinishMessage = "Forecasts posted"; </script> <script language="JavaScript" src="countdown.js"></script> This might be a stupid question, but is there any memory usage difference between var variable1, variable2; and var variable1; var variable2;? I'm learning how to use faster code hence the question.
How do i set a page element as a variable and change it? Ive googled the internet like crazy for an answer for this, but couldnt find it. Im trying to create an animation. My question is, how do i change the width of a div onclick? Essentially, I want it to add one percent of the value of the width of the div every one second.. PHP Code: <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Loading Bar</title> <script> var x = getElementById("loadbar").style.width; function load(){ setTimeout ( "progress()", 1000 ); } function progress(){ x++; } </script> </head> <body> <div id="load" style="border:thin solid #6699FF; width:300px; height:10px"> <div id="loadbar" style="background:#6699CC; width:0%; height:100%"> </div> </div> <a href="#" onclick="load()">Click to load</a> </body> I have a page with multiple drop down menus for selecting a State then City, then Zip. The State and City both work fine but I can't seem to make the Zip function properly. Page with drop downs: Code: var xmlhttp; function showCity(state) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="get_cities.php"; url=url+"?q="+state; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } var s=state; function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } var xmlhttp; function showZip(city) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="get_zips.php"; url=url+"?z="+city; url=url+"&q="+s; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged1; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged1() { if (xmlhttp.readyState==4) { document.getElementById("txtZip").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } <!--********** state drop down *********--> <? $State = mysql_query("SELECT DISTINCT full_state FROM zip_codes ORDER by full_state",$db_link); ?> <select name="state" CLASS="formTextbox" size="1" onChange="showCity(this.value)"> <? while($get = mysql_fetch_array($State)) { ?> <option value="<?=$get['full_state'];?>"><?=$get['full_state'];?></option><? } ?> </select> get_cities.php: Code: <?php $q=$_GET["q"]; include('include/db_con.php'); ?> <? $City = mysql_query("SELECT DISTINCT city FROM zip_codes WHERE full_state = '$q' ORDER BY city",$db_link); ?> <select name="city" CLASS="formTextbox" size="1" onChange="showZip(this.value)"> <? while($get = mysql_fetch_array($City)) { ?> <option value="<?=$get['city'];?>"><?=$get['city'];?></option><? } ?> </select> get_zips.php: Code: <?php $z=$_GET["z"]; $q=$_GET["q"]; include('include/db_con.php'); ?> <? $Zip = mysql_query("SELECT DISTINCT zip FROM zip_codes WHERE city = '$z' AND full_state = '$q' ORDER by zip",$db_link); ?> <select name="zip" CLASS="formTextbox" size="1"> <? while($get = mysql_fetch_array($Zip)) { ?> <option value="<?=$get['zip'];?>"><?=$get['zip'];?></option><? } ?> </select> I have my page set to only show the drop down's when there is a value to select. The Zip drop down shows up at the correct time but is empty. I've tried searching the forum but since I'm still learning js I wasn't able to make use of any on the other multiple drop down examples I came accross. Thanks for any advice you can offer. Hi, Sorry very beginner in JS I am using formmail and JS to collect booking info calculates a total and sends to email. Formmail redirects to a thankyou page. Here I can send the total to paypal. I have looked and looked, but cant work out how to pass the total from the booking form to the thankyou page. How can I do this simply. Code not supplied because its nothing wonderous. Thanks I have a html page with a lot of thumbnails. The idea is that when the user clicks on an image the onClick event is to display another detailed form and deliver to that form the name of the image in a variable. In the detailed php-form there is a query to MySQL to retrieve a record. The record will be retrieved by a Query based on the name of the picture. Apparently the PHP cannot do the job. I had an idea to make the thumbnail page as a form and to use use a hidden field with the thummnail name which should be carried on with the $_POST array through the submit button but i do not want to have a submit button. The more elegant way is just by clicking the picture the detailed page is opened and the variable is transferred where my php code can make use of the variable for the query. I have never used java before so you have to excuse for the lack of knowledge. Can anyone gie me an idea how i should implemnt this Best regards MSP I have a html page with a lot of thumbnails. The idea is that when the user clicks on an image the onClick event is to display another detailed form and deliver to that form the name of the image in a variable. In the detailed php-form there is a query to MySQL to retrieve a record. The record will be retrieved by a Query based on the name of the picture. Apparently the PHP cannot do the job. I had an idea to make the thumbnail page as a form and to use use a hidden field with the thummnail name which should be carried on with the $_POST array through the submit button but i do not want to have a submit button. The more elegant way is just by clicking the picture the detailed page is opened and the variable is transferred where my php code can make use of the variable for the query. I have never used java before so you have to excuse for the lack of knowledge. Can anyone gie me an idea how i should implemnt this Best regards MSP Hi, I want to write some javascript code that uses arrays, I have a list of arrays named array1, array2, array3 etc. I want to perform a function on each of these arrays. I wanted to have a variable for the number after array so this is what I have: <code> var array1 = new Array ("1","2","3","4","5"); var array2 = new Array ("5","6","7","8","9"); for (var i=1; i<=2;i++){ document.writeln(("array"+i)[1]); } </code> the problem is it gives me the letters in the string array instead of the array values. How do I get javascript to treat ("array"+i) as array1? Can anyone tell me of how to take or assign a javascript variable into php.
Hi, I'm using ColdFusion to handle the login function for users (see login_form.cfm below). Have to click in the username box to be able to start typing. What's the best way to define the focus to be on the username when the page initially loads? Thanks <form method="post"> Username: <input type="Text" name="username"><br> Password: <input type="Password" name="password"><br> <input type="Submit" value="Login" name="login"> </form> |