JavaScript - Checking/changing The Status Of A Style
How do I check the status of a style?
I thought something like this would work, but no joy: Code: divTest = document.getElementById('link_container'); if (document.divTest.style.display == "none") { } Similar TutorialsHello guys I have a questions: How can I use javascript to change the CSS the page uses? I'm a noob to javascript so please help me out =D Regards, Thunderofnl Hi All I have a piece of script which makes a div slide out from the side of the screen with information on it. I can change the innerHtml etc no problem, but i have a problem with change .style attributes dynamically. My code: Code: var mystring = "height:500px"; var keyVal = mystring.split(":") var slidingDiv = document.getElementById('slidingDiv'); slidingDiv.style.keyVal[0] = keyVal[1]; As you see above i get a value which i need to split() to get the key and value to use. So what i would like to see is: Quote: slidingDiv.style.height = 500px; But it does not work, as there is no such function as slidingDiv.style.keyVal[0]; How do i change this? I hope I've explained this thoroughly enough. Please ask if i need to explain further. Regards Marinus Hi there, I can;t figure out where to change the code/add in code I have installed Fancybox using jQuery and done all the neccessary steps to ensure it works as popup. However I can't find where to add in code/edit code to make my title left for instance or bold type etc. This is the code that calls the fancybox website is: http://www.soltoro.com/NEW/projects/elrayo.html Code: <script> $(document).ready(function() { /* This is basic - uses default settings */ $("a#single_image").fancybox({ 'titlePosition': 'inside' }); /* Using custom settings */ $("a#inline").fancybox({ 'hideOnContentClick': true}); /* Apply fancybox to multiple items */ $("a.group").fancybox({ 'transitionIn' : 'elastic', 'transitionOut' : 'elastic', 'speedIn' : 600, 'speedOut' : 200, 'titlePosition' : 'inside', 'overlayShow' : false }); });</script> Hi i'm in need of some help with a javascript function I have been working day and night trying to get this to work and its almost there, basicly what I am trying to do is create a facebook like status update box with user tagging and member search drop down. Currently I have the status update input where users can enter in their status update, this also has a user tagging system with it which when you type the '@' symbol the friend search displays and once a name is clicked the @ sign plus what you was writing gets replaced with that name but what I am in need of is someone who can sort this problem out, this problem is I want the user to click on the name but once clicked i need the name to show up as a blue link just like facebook do and also i need the backend of the system to check when a name is click to get the id number of that user and set the bbcode in the status area as my bbcode system uses [quote=123432]username[/quote] which is how what quotes the user now I also need to have a rich text area instead of the standard html one as I need the area to display the link and not the bbcode. If any one can help please reply, Thank you, DJCMBear. P.S. Here are the codes I have so far just for someone to over look to see if they can sort it out. The Javascript Class: Code: <script type="text/javascript"> var SDK = { setCursor: function(el) { if(el.selectionStart) { return el.selectionStart; } else if (document.selection) { el.focus(); var r = document.selection.createRange(); if (r == null) { return 0; } var re = el.createTextRange(), rc = re.duplicate(); re.moveToBookmark(r.getBookmark()); rc.setEndPoint('EndToStart', re); return rc.text.length; } return 0; }, displayFriends: function(cp) { var friendSession = document.getElementById('fsi'); var friendSelect = document.getElementById('fs'); var selectText = document.getElementById('fst'); var info = friendSession.value.split(':'); var checker = info[0]; var position = parseInt(info[1]); if(window.event.keyCode == 192 && friendSession.value == 0) { friendSelect.style.display = 'block'; friendSession.value = 1+':'+this.setCursor(cp); } else if(friendSession.value == 0) { friendSelect.style.display = 'none'; } else if(friendSession.value == 1 && window.event.keyCode == 8 && selectText.value.substr(position,1) != "@") { friendSession.value = 0; friendSelect.style.display = 'none'; } }, selectFriend: function(selection) { var input = document.getElementById('fst'); var info = document.getElementById('fsi').value.split(':'); var checker = info[0]; var position = parseInt(info[1]); if(checker == 1) { input.focus(); input.value = input.value.substring(0,position)+selection.innerHTML+' '; document.getElementById('fsi').value = 0; document.getElementById('fs').style.display = 'none'; input.focus(); } }, shrink: function(current,newid) { var friendSession = document.getElementById('fsi'); var old = document.getElementById(newid); if(current.value == '' && friendSession.value.substring(0,1) != 1) { current.style.display = 'none'; current.value = ''; old.style.display = 'block'; } }, grow: function(current,newid) { var input = document.getElementById(newid); current.style.display = 'none'; input.style.display = 'block'; input.style.height = '70px'; input.focus(); }, StatusForm: function(info) { var form = "<div id=\"statusUpdater\"><div onclick=\"SDK.grow(this,\'fst\');\" id=\"dfst\">"+info.defaultTxt+"</div>"; form += "<textarea style=\"display:none;\" id=\"fst\" onclick=\"SDK.grow(this,'fst');\" onblur=\"SDK.shrink(this,'dfst');\" onkeydown=\"SDK.displayFriends(this);\" onkeyup=\"SDK.displayFriends(this);\"></textarea>"; form += "<input type=\"hidden\" id=\"fsi\" value=\"0\" /><div id=\"fs\" style=\"display:none;\">"; form += "<ul><li onclick=\"SDK.selectFriend(this);\" style=\"cursor:pointer;\">Bobby Frank</li>"; form += "<li onclick=\"SDK.selectFriend(this);\" style=\"cursor:pointer;\">Dan Dave</li>"; form += "<li onclick=\"SDK.selectFriend(this);\" style=\"cursor:pointer;\">John Doe</li></ul></div></div>"; document.write(form); } } </script> The CSS Styles: Code: <style type="text/css"> * { margin: 0; padding: 0; } #statusUpdater { width: 500px; margin: 30px auto; } #fst { width: 100%; } #dfst { width: 98.5%; } #fst, #dfst { font-family: arial; padding: 3px; font-size: 14px; resize: none; border: 1px solid #666; color: #666; cursor: text; background: #fff; overflow-y: auto; height: 16px; } #fs { margin: 0; width: 99.8%; border: 1px solid #000; border-top: 0px; } #fs ul { list-style: none; } #fs li { padding: 3px; } </style> The Javascript Form Call: Code: <script type="text/javascript">SDK.StatusForm({'defaultTxt':'What\'s on your mind?','action':'http:\/\/www.example.com\/ajax\/statusPost.ax'});</script> Is the window.status still useful nowadays or is it outdated? If it is still used, why doesn't this work please? Code: <a href="javascript_status_bar_messages.cfm" onMouseover="JavaScript:window.status='Status Bar Message goes here'; return true" onMouseout="JavaScript:window.status=''; return true">Hover over me!</a> Hi All I have a list of links on my website with anchors coded the following way: <ul class="fav"><a href="/cgi-bin/send.pl?ID=XX" onMouseOver="window.status='http://www.domain.com'; return true;" onMouseOut="func_clear(); return true;" onClick="stat(294);" target="_blank">Linked domain name</a></ul> Then I have found on http://www.askthecssguy.com/2006/12/..._favicons.html a javascript to display a favicon image before each one of my links in the list; this script is working fine when getting the domain name from href value. But in my case the suitable domain name to load each favicon is present in window.status value. I have played a bit with the above scripts and finally I'm trying to use the following function: Code: function faviconizeFavicon() { if (!document.getElementsByTagName) return false; if (!document.createElement) return false; var ul = document.getElementsByTagName("ul"); for (var i=0; i<ul.length; i++) { if (ul[i].className == "fav") { var links = ul[i].getElementsByTagName("a"); for (var j=0; j<links.length; j++) { var hrefvalue = links[j].parentNode.innerHTML; var domain = 'default_favicon.gif'; domain = hrefvalue.match(/(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)\'/g); try{ var cue1 = document.createElement("img"); cue1.className = "favicon"; cue1.src = 'default_favicon.gif'; cue1.id = 'img' +i+ j; links[j].parentNode.insertBefore(cue1,links[j]); var cue = document.createElement("img"); cue.className = "favicon"; var cuesrc = "http://"+ domain + "/favicon.ico"; cuesrc = cuesrc.replace("http://http://","http://"); cuesrc = cuesrc.replace("'/favicon.ico","/favicon.ico"); cue.setAttribute("imgid",'img' +i+ j); cue.setAttribute("src",cuesrc); cue.onload = function () { document.getElementById(this.getAttribute("imgid")).src = this.src; } cue.setAttribute("src",cuesrc); } catch ( ex ) { } } } } } This javascript should display first the default locally available favicon gif before each link and then try to load original favicons from each domain and display them at the place of default favicon gif only if available. The above code works with any console errors but very randomly and not with all websites ?? Some favicons are loaded from distant websites and some of them never, independing of network quality or other factors! So I'm wondering why this code is not working for each link ? My question is: could you please have a look on my following Regex if this should work in every case with each domain name ? domain = hrefvalue.match(/(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)\'/g); I put the apostrophe at the end because my url in window.status is always ended by a single closing. Also I'm asking if taking into account that ONLY my window.status value is placed between single apostrophes and ALL other values of my anchors are opened and closed with double apostrophes, maybe it would be easier to get my domain value searching for any value between two single apostrophes ?? My another question is: Is it possible that other javascripts present in my html code could interfere with this script and make it working randomly ? Thanks in advance for any clues Hi. I'm currently putting together a website. On one of my pages, I get "Error on page" in the status bar when viewing it in Internet Explorer. I don't get this message in Firefox. I have an external javascript (code below) for tooltips on the webpage. I did not write the script, I merely changed one or two things. When I double click the status bar to see what the message is, it says: 'tt.timer' is null or not an object. Line: 70 Char: 3 I'm new to javascript, and so I'm not sure of what I need to alter. Can anyone see what i'm missing/doing wrong? Any help would be really appreciated! Code: var tooltip=function(){ var id = 'tt'; var top = 3; var left = 3; var maxw = 300; var speed = 60; var timer = 20; var endalpha = 95; var alpha = 0; var tt,t,c,b,h; var ie = document.all ? true : false; return{ show:function(v,w){ if(tt == null){ tt = document.createElement('div'); tt.setAttribute('id',id); t = document.createElement('div'); t.setAttribute('id',id + 'top'); c = document.createElement('div'); c.setAttribute('id',id + 'cont'); b = document.createElement('div'); b.setAttribute('id',id + 'bot'); tt.appendChild(t); tt.appendChild(c); tt.appendChild(b); document.body.appendChild(tt); tt.style.opacity = 0; tt.style.filter = 'alpha(opacity=0)'; document.onmousemove = this.pos; } tt.style.display = 'block'; c.innerHTML = v; tt.style.width = w ? w + 'px' : 'auto'; if(!w && ie){ t.style.display = 'none'; b.style.display = 'none'; tt.style.width = tt.offsetWidth; t.style.display = 'block'; b.style.display = 'block'; } if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'} h = parseInt(tt.offsetHeight) + top; clearInterval(tt.timer); tt.timer = setInterval(function(){tooltip.fade(1)},timer); }, pos:function(e){ var u = ie ? event.clientY + document.getElementById('faqid').scrollTop : e.pageY; var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX; tt.style.top = (u - h) + 'px'; tt.style.left = (l + left) + 'px'; }, fade:function(d){ var a = alpha; if((a != endalpha && d == 1) || (a != 0 && d == -1)){ var i = speed; if(endalpha - a < speed && d == 1){ i = endalpha - a; }else if(alpha < speed && d == -1){ i = a; } alpha = a + (i * d); tt.style.opacity = alpha * .01; tt.style.filter = 'alpha(opacity=' + alpha + ')'; }else{ clearInterval(tt.timer); if(d == -1){tt.style.display = 'none'} } }, hide:function(){ clearInterval(tt.timer); tt.timer = setInterval(function(){tooltip.fade(-1)},timer); } }; }(); I've started studying JavaScript recently. The following simple scenario from the Russian textbook is not implemented properly on my PC. Code: <HTML> <HEAD> <TITLE>Link Description</TITLE> <SCRIPT LANGUAGE="JavaScript"> function describe(text) { window.status = text; return true; } function clearstatus() { window.status=""; } </SCRIPT> </HEAD> <BODY> <h1>Link Description</h1> <P><i>Put mouse pointer over links to display their description</i></P> <ul> <li><A HREF="order.html" onMouseOver="describe('Закажите товар'); return true;" onMouseOut="clearstatus()";> Заказ товаров</A> <li><A HREF="email.html" onMouseOver="describe('Направьте письмо'); return true;" onMouseOut="clearstatus()";> Email</A> <li><A HREF="complain.html" onMouseOver="describe('Раскритикуйте все'); return true;" onMouseOut="clearstatus()";> Отдел защиты прав потребителей</A> </ul> </BODY> </HTML> I just typed the script from the book char by char. I use Firefox browser, v.3.5.7. The error console does not display any mistakes. Please, explain me why on placing mouse over a link the status bar displays A HREF text instead of the link description. I am wanting to allow a user to update their twitter status from my website. I was planning on using Twitter's @anywhere feature, but this was not a very friendly solution: Take over 3 seconds to load Makes 14 requests Calls jQuery twice Then I found the Twitter REST API: https://dev.twitter.com/docs/api Using OAuth, I want the user to be able to login, and then update their status using that API. I've been trying to find tutorials on this, but I haven't found any that use the REST API to update the Twitter Status. Does anyone have code for/know of a tutorial for what I'm looking for? I have a simple problem, I can't get the status bar to change. I am very new to javascript, and I am trying to practice some simple commands, and the onMouseOver event is suppose to change the status bar in my window. I can get it to change for onMouseOut but not onMouseOver. Here is what I have so far <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>Exam</TITLE> </HEAD> <BODY> <H3>My Page</H3> <a href="http://www.google.com" onMouseOver="window.status='Visit google.';return true;" onMouseOut="window.status='Come back soon ';return true;">Visit Google</a> </BODY> </HTML> Hello guys, The following excerpt is part of a very huge project(in terms of code involved). Pardon me if it lacks a bit of context. But I assume I have posted adequate information for understanding the problem. Code: var sztitlebar_specific= "<table cellpadding='0px' cellspacing='0px' width='100%'><tr>" +"<td class='tiletitle'>" "<img src='../images/alert.gif' onclick='toggleAlerts(\"#ID#\")' alt='Toggle Alerts' title='Toggle Alerts' style='cursor: hand'>" + "<input type='checkbox' name='pricesonlycb' onclick='parent.applyFilterPricesOnly(\"#ID#\",pricesonlycb.checked,mypricesonlycb.checked,\"#NAME#\")'>" + "<input type='checkbox' name='mypricesonlycb' onclick='parent.applyFilterPricesOnly(\"#ID#\",pricesonlycb.checked,mypricesonlycb.checked,\"#NAME#\")'>" + "<td class='tiletitle' style='text-align: center'>#NAME#</td>" + </tr></table>"; The onclick event fires without any trouble, and the following function is called. Code: function applyFilterPricesOnly(filterid, pricesonly, mypricesonly,filtername){ alert("applyFilterPricesOnly called: filterid =" + filterid + "filtername =" + filtername + "mypricesonly =" + mypricesonly + " pricesonly=" + pricesonly); } But when I alert the status of the checkboxes they show up as "undefined". As you can see, the first piece of code defines a titlebar with a button and a couple of checkboxes and the name of the titlebar. And it is these checkboxes that remain undefined even though I can see them and check and uncheck them. But the name of the titlebar gets passed to the function correctly when the onclick event fires and it gets alerted. Where am I going wrong? if I have an html page that uses the <style> or a <link> to call a style sheet these properties aren't available to JavaScript is there a good way to access them? eg Code: <html> <head> <title>expandable text area</title> <style type="text/css"> #expandable{ height: 100px; } </style> </head> <body> <form> <textarea id="expandable" cols="30" rows="10"></textarea> </form> </body> <script type="text/javascript"> document.getElementById('expandable').addEventListener('click',function(){ if(!this.style.height){ this.style.height = this.scrollHeight+'px'; } alert(this.style.height); }, true); </script> </html> In this example I have the height set but I cannot access it since it is not declared in the style attribute of the html element Hi, I am writing an application which needs to open a modal dialog window in a secure connection. I am able to open the dialog using HTTPS, but on the status bar I cannot see the SSL Padlock. The application is being written in .NET and the browser I use is IE 6.0. Any suggestions and feedback are welcome. Regards Totre Hello, i wanna use NiceEdit text editor in my site. but when i load the editor page, always i find the editor non-active, i have to click inside the textarea to active the textarea and the editor. have a look at the demo here http://nicedit.com/demos.php so i want to set the editor default status active without clicking inside the textarea to active it, so how can i do that please ?? thanks Hi All, I have a form that captures member registration details. In the admin section .. I would like to change the Status field of a record/s from NEW to PAYMENT DUE after 14 days from the data of submission. The status change should automatically trigger on the 15th day. So when the admin checks the list page he/she should be able to view the updated status field. Any pointers how to accomplish this? Thanks in advance. Vinny Hi, I am trying to implement something like a javascript that can click and focus the Status Update Box on Facebook. Till now, I have nothing in hand that can perform the task so I thought about a javascript that can do it. I am not even a newbie to javascript but I know that it can perform various complicated tasks on client side. Can anyone here tell me how do I click the Status Update box and set it to focused by a javascript so that when I start typing the Status box receive the text ? Thanks Hi there, I hope I post this in the right section. I'm trying to do a redirect using the below code: <script type="text/javascript"> window.location.href = "http://google.com" </script> FF and IE work as they should. Chrome doesn't. The request above to http://google.com, gets a 'canceled' status in Chrome browser > Development tools > "Network". I've tried several other functions: location.href = url location.replace(url) document.location = url location.assign(url) window.open(url, '_self') Same code pasted within a local html file works fine. Below is the redirect request that it's canceled by chrome: http://pastebin.com/hD36M1RG Any clues? Thanks I keep getting myself into trouble because I tend to use my Java reference when coding Javascript, and of course Javascript doesn't support all Java functions. I've just discovered that apparently Javascript doesn't support the trim() function. But curiously, if I code it as: mystring.trim() then Firefox will handle it without any errors. (I haven't actually checked to see if whitespace is removed from around the string.) But when I code it like this: trim(mystring) then firefox gives an error. I've also found a couple of situations where I've made syntax errors, and Firefox gives no error message. This makes debugging tricky, since the only resource I have available is Firefox's Error Console. Safari has no error reporting whatsoever, AFAIK. MSIE seems to find some errors that Firefox misses, but I don't have MSIE on my main computer, so it's a nuisance to use. As a hobbyist, I have no budget to buy Javascript development tools. Is there something free available that does a better job of finding errors? I need to check to see if a cookie has been previously created: Code: var startnum = readCookie('a1'); if (document.cookie.indexOf('a1') == -1){ var startnum = "0"; } Should line 2 be: Code: if (document.cookie.indexOf('a1') == null){ ? Does == -1 do the same thing? hello, This seems very basic, but I am running into a complication. What I would like to do is check if a certain div is displayed or hidden (really doesnt matter which) then set a map zoom level based upon that. here is my current function. function closeDirections(){ gdir.clear(); if(document.getElementById("river").style.display="none"){ map.setZoom(16); hideID('river'); showID('main'); } if(document.getElementById("main").style.display="none"){ map.setZoom(12); hideID('main'); showID('river'); } } Also here is a link to my map, just in case. map I have tried several variations, but from what I can tell with every instance, it only examines the first and never considers the second "if". I thought to rememdy this issue by using if/else...same issue. The only thing I could think is a nested if statements, but I am not sure what to use as a parent if. I have searched for a while, but cannot seem to find something like an .is_hidden(). Something that I could see if its true/false. Any help would be very much appreciated. |