JavaScript - Connect Variable With Element?
I wrote a script that registers scrolling action as a number, and is stored in the variable delta. Now, I only want to use that variable when scrolling over the div section1 on the page. What would that look like ... this?
Code: function something() { if(section1.delta < 0) do something here; } Similar TutorialsHey all, I'm a new Javascript coder; it's still pretty easy for me to get snagged on stuff. Anyways, I had a question for a specific project I've been trying to figure out. I have an element set with CSS to a width of 160px. What I want is a way for users to the site to drag a slider back and forth to set the width of the button. Some sort of smooth animation while this is happening would also be nice. I'd also like a way to set a max width on the element. So, can this be done? I'm guessing it would use jQuery, but I don't really know. Does anyone have any ideas? AA 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> The bit of code in bold in the code below is giving me this error in IE: Error: Code: Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; Tablet PC 2.0; InfoPath.2; OfficeLiveConnector.1.4; .NET CLR 3.0.30729; OfficeLivePatch.1.3; MSN OptimizedIE8;ENGB) Timestamp: Tue, 16 Mar 2010 15:07:11 UTC Message: HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917) Line: 0 Char: 0 Code: 0 URI: http://www.mateinastate.co.uk/users/mateinastate Code: Code: if(document.getElementById('msn1').innerHTML=="") { document.getElementById('msn1').style.display='none'; } if(document.getElementById('yahoo1').innerHTML=="") { document.getElementById('yahoo1').style.display='none'; } if(document.getElementById('skype1').innerHTML=="") { document.getElementById('skype1').style.display='none'; } if(document.getElementById('facebook1').innerHTML.toLowerCase().substr(0,18)=='<a href="http://">') { document.getElementById('facebook1').style.display='none'; } else if(document.getElementById('facebook1').innerHTML.toLowerCase().substr(0,11)=='<a href="">') { document.getElementById('facebook1').style.display='none'; } else { document.getElementById('fbook-add').innerHTML='Facebook Profile'; } What it's saying isn't actually true (I don't think)... this is how the section is laid out: Code: <div id="submenu1" class="anylinkcss"> <ul> <li class="contact-pm"><a href="/index.php?do=pm&act=new&to=$RateViewProfileUserName$&returnurl=$ReturnURL$">PM me</a></li> <li class="contact-email"><a href="/index.php?do=email&id=$RateViewProfileUserId$">E-mail me</a></li> <li class="contact-msn" id="msn1">$RateViewProfileUser-profile_msn$</li> <li class="contact-yahoo" id="yahoo1">$RateViewProfileUser-profile_yahoo$</li> <li class="contact-skype" id="skype1">$RateViewProfileUser-profile_skype$</li> <li class="contact-facebook" id="facebook1"><a href="$RateViewProfileUser-profile_facebook$"><span id="fbook-add"></span></a></li> </ul> </div> <script type="text/javascript" src="/html_1/js/contact-information.js"></script> Does anyone know why this might error in just IE? Hi, I'm relativly new to JS and brand new to the forum so you might need to dumb down your replys for my slightly lacking knowledge. That being said I do have a very solid grasp of html, css and am getting there with JS and its various frameworks. I'm integrating wordpress into an existing site for a friend and currently have the main blog page appear in a DIV. This is the best way to integrate in this case due to many reasons mostly of way the site is constructed. Code: <div class="scroll-pane" id="scrollbox"> WORDPRESS BLOG </div> My issue is that links within that DIV, in the blog, when clicked redirect the page. The simple answer to this would be to have them just open in a new page, which I can easily do with the below code. Code: function Init() { // Grab the appropriate div theDiv = document.getElementById('scrollbox'); // Grab all of the links inside the div links = theDiv.getElementsByTagName('a'); // Loop through those links and attach the target attribute for (var i=0, len=links.length; i < len; i++) { // the _blank will make the link open in new window links[i].setAttribute('target', '_blank'); } } window.onload = Init; But what I'd rather it do is have any link clicked inside the DIV to reload in that same DIV, similar to an iframe, but obviously without using an iframe, due to it's compatibility issues. Is this possible by editing the above code? If not what do I need? Thanks in advance for any help! Hello, I am very new to HTML. Yesterday I have started learning HTML. I want to make two Dropdown but should be linked with each other. There value should change after click "go" button. In other word I want to make one html for Post Code/Pin Codes of my state. Please Help Me!!! I have made script till he <html> <body> <table width="500" border="0"> <tr> <td colspan="2" style="background-color:#FFA500;"> <h1>PIN CODES OF GOA</h1> </td> </tr> <tr valign="top"> <td style="background-color:#FFD700;width:100px;text-align:top;"> <b>GOA</b><br /> BEACHES<br /> CHURCHES<br /> BARS </td> <td style="background-color:#eeeeee;height:200px;width:400px;text-align:top;"> </body> </html> </body> <form> <select name="menu" style="width:200px;"="font-family:'Arial';color:#FFFFFF;background-color:#000000;font-size:10pt;"> <option value=VASCO</option> <option value=FATORDA</option> </select> <select name="menu" style="width:200px;"="font-family:'Arial';color:#FFFFFF;background-color:#000000;font-size:10pt;"> <option value="403802"</option> <option value="403602"</option> </select> <input type="button" onClick="location=this.form.menu.options[this.form.menu.selectedIndex].value;" value="GO" style="font-family:'Arial';color:#FFFFFF;background-color:#000000;font-size:10pt;"> </form> <script type="text/javascript"> tday =new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); tmonth=new Array("January","February","March","April","May","June","July","August","September","October","Novem ber","December"); function GetClock(){ d = new Date(); nday = d.getDay(); nmonth = d.getMonth(); ndate = d.getDate(); nyear = d.getYear(); nhour = d.getHours(); nmin = d.getMinutes(); nsec = d.getSeconds(); if(nyear<1000) nyear=nyear+1900; if(nhour == 0) {ap = " AM";nhour = 12;} else if(nhour <= 11) {ap = " AM";} else if(nhour == 12) {ap = " PM";} else if(nhour >= 13) {ap = " PM";nhour -= 12;} if(nmin <= 9) {nmin = "0" +nmin;} if(nsec <= 9) {nsec = "0" +nsec;} document.getElementById('clockbox').innerHTML=""+tday[nday]+", "+tmonth[nmonth]+" "+ndate+", "+nyear+" "+nhour+":"+nmin+":"+nsec+ap+""; setTimeout("GetClock()", 1000); } window.onload=GetClock; </script> <div id="clockbox"></div> </td> </tr> <tr> <td colspan="2" style="background-color:#FFA500;text-align:center;"> Search Your Post Code</td> </tr> </table> I was wondering if there's a quick and simple way to notify a user if an ajax connection is broken, for example you're calling a file, but due to your internet connection, the file cannot be relayed back to you, so the existed javascript code on the initial page you're on, notifys you of the problem. Any ideas? Hi, I'm a newbie to javascript programming and I'm seeking on a solution on how to connect to a tcp port using javascript. Basically, we have phone server that is constantly streaming XML data on port 1024 (serverIP:1024). I've ran a packet sniffer and was able to gather the elements and attributes for the XML data that the server is streaming. Now, I have a test XML parser which works with the XML document using the elements and attributes i've gathered from the packet sniffer. Is there a way for me to connect to the TCP port i've mentioned using javascript and incorporate it with the XML parser that I have. Here is the code for my XML Parser. Quote: <html> <body> <script type="text/javascript"> var xmlDoc; if (window.XMLHttpRequest) { xmlDoc=new window.XMLHttpRequest(); xmlDoc.open("GET","acddataentry.xml",false); xmlDoc.send(""); xmlDoc=xmlDoc.responseXML; } // IE 5 and IE 6 else if (ActiveXObject("Microsoft.XMLDOM")) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load("acddataentry.xml"); } document.write("<table border='1'>"); var x=xmlDoc.getElementsByTagName("ACD"); for (i=0;i<x.length;i++) { document.write("<tr><td>"); document.write(x[i].getElementsByTagName("Calls_Waiting")[0].childNodes[0].nodeValue); document.write("</td><td>"); document.write(x[i].getElementsByTagName("Crt_Wait_Time")[0].childNodes[0].nodeValue); document.write("</td></tr>"); } document.write("</table>"); </script> </body> </html> Any help on this is highly appreciated. Thank in advance. HI, Is it possible to connect to a sqlite database via javascript. And I do not mean the HTML 5 Web SQL Database, that is no problem. What I mean is a file-based SQLite database, which is in the same folder as the HTML page.Also, I can not use something like Google's API, only the javascript libraries I can then put in this folder. THX Helge Hello Everyone, I am using Javascript in ASP page to connect to the database. I am not able to figure out where is the problem. Gettting this error-> Quote: Error Type: Microsoft OLE DB Provider for SQL Server (0x80004005) [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied. /MyWeb/test.asp, line 9 My code is-> Code: <%@ Language = JavaScript %> <% var myconnection var myrecordset var connectionString myconnection = Server.CreateObject("adodb.connection") connectionString = "Provider=SQLOLEDB.1;Password=myPwd;Persist Security Info=True;User ID=myId;Initial Catalog=MyTable;Data Source=MyCompName\MyDBINSTANCE" myconnection.Open(connectionString, myconnection); %> If someone could please guide me in the right direction I would greatly apprieciate it. Thanking You. Hello there everyone, I've been stuck on this for about a day and a half. My code is for a connect four game in Javascript. The problem resides in the minimax recursion AI function. Code: function bestMove(color,depth,maxDepth) {//Finsd the best move for the side. Returns column and score pair //depth specifies current level of depth (should be passed as 0) //maxDepth specifies the maximum depth to search //holds the best score var best = new Worth(-100000,0); if(depth%2==1)best.Score*=-1; var mv = new Worth(0,0); for (i=0;i<7;i++) { //try putting a piece at each of 7 columns. mv.Column=i; if(height[i]==-1){ }else{ //find the row to put this piece. gameB[height[i]][i]=color; height[i]--; alert(""+i+""); //find if it is a game over, don't search further if it is //a score of 100 or -100 means a game over var cur = new Worth(0,0); cur.Score=checkWin(height[i],i,color); if(cur.Score==gold){ cur.Score=-100; } if(cur.Score==silver){ cur.Score=100; } if(cur.Score==100||cur.Score==-100||depth==maxDepth){ mv.Score=cur.Score; }else{ //search further (this one is the recursive call if(color==gold) { color = silver; }else{ color = gold; } mv.Score=bestMove(color,depth+1,maxDepth).Score; } //if this move is better, use it instead if(mv.Score>best.Score&&depth%2==0) best=mv; else if(mv.Score<best.Score&&depth%2==1) best=mv; //undo the move. Remove the piece you just put if(getIt(height[i],i)==outside) { alert("OH JEEZ"); } } } return best; } I cannot figure out what is wrong exactly. There maybe a serious error of logic within the function. I posted the .html file on my website www.softdrawing.com/connect4.html with the whole code. If someone could help me fix that function please that would be amazing. I'm new to the minimax algorithm and I tried writing it for myself. What I am trying to do is make a little box that when you hover over it, it will move to a random position. What I am having trouble with is the JavaScript. I have made the code for everything, EXCEPT to move it to a random position. Here is my code so far: Code: <style type='text/css'> #circle1 { background:#007fff; height:20px; margin:0px; position:absolute; width:20px; left:5px; top:5px; -webkit-transition:left 2s linear, top 2s linear; } #circle1:hover { left:25px; top:25px; -webkit-transition:left 0s linear, top 0s linear; } </style> <div id='circle1'></div> I would like the left: and top: in the #circle1:hover to be a random number, to make it go to a random position. I have no clue how to do that though... I have this script added to a facebook icon (#id) on my front page: (function() { var e = document.createElement('script'); e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; e.async = true; document.getElementById('fb-root').appendChild(e); })(); window.fbAsyncInit = function() { var fbClicked = false; FB.init({appId: 'Myappid', status: true, cookie: true, xfbml: true}); FB.Event.subscribe('auth.login', function(response) { if(response.session && fbClicked){ window.location = 'http://www.mysite.com/facebookauth/?ref=/'; } }); } function thFBShortCut() { FB.login(function(response) { fbClicked = true; if (response.session && response.perms && fbClicked) { window.location = 'http://www.mysite.com/facebookauth/?ref=/'; } }, {perms:'email,publish_stream'}); } function thFBLogin() { fbClicked = true; $('.popbox').fadeOut(); FB.getLoginStatus(function(response) { if(response.session && response.status == 'connected' && fbClicked) { window.location = 'http://www.mysite.com/facebookauth/?ref=/'; } }); } I want when whenever user press on facebook icon, the script should trigger facebook connect app. I added `<div id="fb-root"></div>` right after `<body <?php body_class(); ?>>`, but when I load my site I keep getting these error messages: document.getElementById("fb-root") is null and FB is not defined [Break On This Error] FB.login(function(response) { My html: <a id="facebookicon" onclick="thFBShortCut()">Login</a> 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... 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 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. 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.
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 |