JavaScript - Can I Make The Javascript In This Form More Efficient?
Hi all,
I've been trying to build a form with dynamic checkboxes. I'd like to have a master 'select none' checkbox in a few form fields which has 2 key functions:- 1) clearing all field boxes the user may have entered before opting to select none 2) disabling all field options to make it impossible for the user to tick both 'none' and other options. This 'select none' checkbox should be ticked by default, so when the user unchecks it, the rest of the field options light up. I'm a complete novice but I have it working ok having stitched a few pieces of code I've found together, however I don't think it's very efficient. I have had to duplicate both bits of the javascript to make it work, changing only the function names in the <head> area ('Uncheck' and 'Uncheck2') and the class variables in the form in the <body> area ('fruit_child' and 'veg_child'). As this form will have several more fields eventually, I'm looking for a better way to do this while maintaining the functionality. Ive read bits about object-orientated programming which may be what I'm looking for to make this more efficient, but I'm not sure how to implement it in this example. Can a more experienced coder please help? Kind thanks, Fleef Code: <head> <SCRIPT LANGUAGE="JavaScript"> // Check_ctr: clears all when 'none' box ticked --> function Uncheck(chk) { if(document.myform.Check_ctr.checked==true){ for (i = 0; i < chk.length; i++) chk[i].checked = false ; } } // End --> </script> <SCRIPT LANGUAGE="JavaScript"> // Check_ctr: clears all when 'none' box ticked --> function Uncheck2(chk_veg) { if(document.myform.Check_ctr_veg.checked==true){ for (i = 0; i < chk_veg.length; i++) chk_veg[i].checked = false ; } } // End --> </script> </head> <body> <form name="myform" method="post"> <input type="checkbox" id="none_fruit" name="Check_ctr" value="yes" onClick="Uncheck(document.myform.fruit)" checked><b>None</b><br> <input type="checkbox" name="fruit" value="1" class="fruit_child" disabled="true">1<br> <input type="checkbox" name="fruit" value="2" class="fruit_child" disabled="true">2<br> <input type="checkbox" name="fruit" value="3" class="fruit_child" disabled="true">3<br> <input type="checkbox" name="fruit" value="4" class="fruit_child" disabled="true">4<br> <input type="checkbox" name="fruit" value="5" class="fruit_child" disabled="true">5<br> <script> // disables options when 'none' ticked --> $(function(){ $("#none_fruit").click ( function() { if ( !$(this).is ( ":checked" ) ) { $(".fruit_child").removeAttr ( "disabled" ); } else { $(".fruit_child").attr ( "disabled" , true ); } }); });</script> <br><br><br> <input type="checkbox" id="none_veg" name="Check_ctr_veg" value="yes" onClick="Uncheck2(document.myform.veg)" checked><b>None</b><br> <input type="checkbox" name="veg" value="1" class="veg_child" disabled="true">1<br> <input type="checkbox" name="veg" value="2" class="veg_child" disabled="true">2<br> <input type="checkbox" name="veg" value="3" class="veg_child" disabled="true">3<br> <input type="checkbox" name="veg" value="4" class="veg_child" disabled="true">4<br> <input type="checkbox" name="veg" value="5" class="veg_child" disabled="true">5<br> <script> // disables options when 'none' ticked --> $(function(){ $("#none_veg").click ( function() { if ( !$(this).is ( ":checked" ) ) { $(".veg_child").removeAttr ( "disabled" ); } else { $(".veg_child").attr ( "disabled" , true ); } }); });</script> </form> Similar TutorialsDoes anyone know how to make URL links that use Javascript still work when users have Javascript disabled on their browser? The only reason I'm using JS on a URL is because my link opens a PDF file, and I'm forcing it not to cache so users have the latest version. I tried the <script><noscript> tags, but I'm not sure if I'm using it correctly, as my URL completely disappears. Below is my HTML/Javascript code: <p class="download"> <script type="text/javascript">document.write("<span style=\"text-decoration: underline;\"><a href=\"javascript:void(0);\" onclick=\"window.open( 'http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf?nocache='+ Math.floor( Math.random()*11 ) );\" >The Child Magazines Media Kit</a></span> (PDF 1 MB) ");</script> <noscript><span style="text-decoration: underline;"><a href="http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf" >The Child Magazines Media Kit</a></span> (PDF 1 MB)</noscript> </p> Thanks for any help, Michael Right now I am using the following method to show/hide divs containing videos. html Code: <div class="vidPop" id="vidPop"> <div class="vidFrame" id="vidFrame"> <iframe id="Iframe1" src="http://player.vimeo.com/video/xxxxxxx1" width="640" height="360" frameborder="0"></iframe> <div class="vidClose"><a href="#" onclick="vidPopdown()"><img src="images/closeban.png" width="52" height="52" alt="close" /></a></div> </div> </div> <div class="vidPop2" id="vidPop2"> <div class="vidFrame2" id="vidFrame2"> <iframe id="Iframe2" src="http://player.vimeo.com/video/xxxxxxx2" width="640" height="360" frameborder="0"></iframe> <div class="vidClose"><a href="#" onclick="vidPopdown2()"><img src="images/closeban.png" width="52" height="52" alt="close" /></a></div> </div> </div> js Code: function vidPopup() { var o = document.getElementById('vidPop'); o.style.visibility = 'visible'; o = document.getElementById('vidFrame'); o.style.visibility = 'visible'; } function vidPopdown() { var o = document.getElementById('vidPop'); o.style.visibility = 'hidden'; o = document.getElementById('vidFrame'); o.style.visibility = 'hidden'; document.getElementById('Iframe1').src = document.getElementById('Iframe1').src } function vidPopup2() { var o = document.getElementById('vidPop2'); o.style.visibility = 'visible'; o = document.getElementById('vidFrame2'); o.style.visibility = 'visible'; } function vidPopdown2() { var o = document.getElementById('vidPop2'); o.style.visibility = 'hidden'; o = document.getElementById('vidFrame2'); o.style.visibility = 'hidden'; document.getElementById('Iframe2').src = document.getElementById('Iframe2').src } all of this works just fine, but now I am adding yet another video, and I know that this isn't the best way to go about doing this. I ought to be able to use 1 function and tell it which iframe to load, however I dont really know javascript. Any and all help on this would be greatly appreciated. Right.. I'm still new to javascript so i've just been messing about with some code and came up with a pointless small program i just wanted to know if the code written is efficient? in other words are there other ways that would be more suitable or are certain parts of the code wrong? The script basically does this. 1. prompts you to enter a time interval in the range of 1 second to 10 seconds 2. A small box appears with a random number generated at the time interval the user entered. IF you enter a number lower or higher then in that range it prompts you again to enter a valid number. If you click cancel you automatically get a time interval of 1 second Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>JavaScript</title> <style type="text/css"> #textbox1{border:1px solid #999;} #fieldsetid{width:157px; border:1px solid #777; font-family:Verdana; margin: 0 auto 0 auto;} </style> <script type="text/javascript"> var count = 0; //Time interval in seconds. do { var getNewValue = prompt("please enter in seconds the interval time", secondTime); var count = getNewValue; if(getNewValue == null){ var count = 1; } if(count > 10){ var secondTime = "please enter a number from 1 to 10"; } } while(count < 1 || count > 10); function makeNumNow() { var MakeNum = Math.random() * 12345678901234567; var result = Math.round(MakeNum); document.form1.textbox1.value = result; } setInterval("makeNumNow()", count*1000); </script> </head> <body> <script type="text/javascript"> </script> <fieldset id="fieldsetid"> <legend>Random Number</legend> <form name="form1"> <input id="textbox1" type="text" name="textbox" value="" /> </form> </fieldset> </body> </html> What is the most efficient type of chat to make? From what I see online most people use a database and limit the number of results they return, but I noticed that some chats, like google and facebook, for some reason are able to load the full chat and get results almost instantly. How do they do it? I would love to make a replica of a google chat and just redesign the way it looks. If anyone can help me with the javascript/php part of this, that would be great. thanks! So I made myself this code so I could have a file upload input field, and the option to add more fields. but it got really big, and I have a fixed number of fields, can't quickly change the number I want. here's my javascript: Code: function new_field(id) { var f = document.getElementById(id); if(f.style.display == 'none') f.style.display = 'block'; } function hide_mais(id) { var g = document.getElementById(id); g.style.display = 'none'; } and the html: Code: <form> <div id="file_a" style="display:block"><input type="file" /><a href="#" id="link_a" onclick="new_field('file_b');hide_mais('link_a')">mais</a></div> <div id="file_b" style="display:none"><input type="file" /><a href="#" id="link_b" onclick="new_field('file_c');hide_mais('link_b')">mais</a></div> <div id="file_c" style="display:none"><input type="file" /><a href="#" id="link_c" onclick="new_field('file_d');hide_mais('link_c')">mais</a></div> <div id="file_d" style="display:none"><input type="file" /><a href="#" id="link_d" onclick="new_field('file_e');hide_mais('link_d')">mais</a></div> <div id="file_e" style="display:none"><input type="file" /><a href="#" id="link_e" onclick="new_field('file_f');hide_mais('link_e')">mais</a></div> <div id="file_f" style="display:none"><input type="file" /><a href="#" id="link_f" onclick="new_field('file_g');hide_mais('link_f')">mais</a></div> <div id="file_g" style="display:none"><input type="file" /><a href="#" id="link_g" onclick="new_field('file_h');hide_mais('link_g')">mais</a></div> <div id="file_h" style="display:none"><input type="file" /><a href="#" id="link_h" onclick="new_field('file_i');hide_mais('link_h')">mais</a></div> <div id="file_i" style="display:none"><input type="file" /><a href="#" id="link_i" onclick="new_field('file_j');hide_mais('link_i')">mais</a></div> <div id="file_j" style="display:none"><input type="file" /><a href="#" id="link_j" onclick="new_field('file_k');hide_mais('link_j')">mais</a></div> <div id="file_k" style="display:none"><input type="file" /><a href="#" id="link_k" onclick="new_field('file_l');hide_mais('link_k')">mais</a></div> <div id="file_l" style="display:none"><input type="file" /><a href="#" id="link_l" onclick="new_field('file_m');hide_mais('link_l')">mais</a></div> <div id="file_m" style="display:none"><input type="file" /><a href="#" id="link_m" onclick="new_field('file_n');hide_mais('link_m')">mais</a></div> <div id="file_n" style="display:none"><input type="file" /><a href="#" id="link_n" onclick="new_field('file_o');hide_mais('link_n')">mais</a></div> <div id="file_o" style="display:none"><input type="file" /><a href="#" id="link_o" onclick="new_field('file_p');hide_mais('link_o')">mais</a></div> <div id="file_p" style="display:none"><input type="file" /><a href="#" id="link_p" onclick="new_field('file_q');hide_mais('link_p')">mais</a></div> <div id="file_q" style="display:none"><input type="file" /><a href="#" id="link_q" onclick="new_field('file_r');hide_mais('link_q')">mais</a></div> <div id="file_r" style="display:none"><input type="file" /><a href="#" id="link_r" onclick="new_field('file_s');hide_mais('link_r')">mais</a></div> <div id="file_s" style="display:none"><input type="file" /><a href="#" id="link_s" onclick="new_field('file_t');hide_mais('link_s')">mais</a></div> <div id="file_t" style="display:none"><input type="file" /><a href="#" id="link_t" onclick="new_field('file_u');hide_mais('link_t')">mais</a></div> <div id="file_u" style="display:none"><input type="file" /><a href="#" id="link_u" onclick="new_field('file_v');hide_mais('link_u')">mais</a></div> <div id="file_v" style="display:none"><input type="file" /><a href="#" id="link_v" onclick="new_field('file_w');hide_mais('link_v')">mais</a></div> <div id="file_w" style="display:none"><input type="file" /><a href="#" id="link_w" onclick="new_field('file_x');hide_mais('link_w')">mais</a></div> <div id="file_x" style="display:none"><input type="file" /><a href="#" id="link_x" onclick="new_field('file_y');hide_mais('link_x')">mais</a></div> <div id="file_y" style="display:none"><input type="file" /><a href="#" id="link_y" onclick="new_field('file_z');hide_mais('link_y')">mais</a></div> <div id="file_z" style="display:none"></div> </form> any suggestions of a more efficient way to do that? also a button to reset form into initial state, with one field only, without having to refresh the page would be cool. thanks in advance If you go to a Youtube video by Justin Bieber or Rebecca Black, comments are constantly being posted and it seems like the autorefresh for the comments kicks in every half second. I don't plan on having millions of users viewing my page, but still, wouldn't having every user make a [mysql] request to the server every half second really take a toll on the server (especially since I don't plan to ever have the resources that Youtube has)? Facebook also seems to have instantaneous auto-refreshes, be it in comment boxes or their chat interface. So what would be the best method to implement a near-instantaneous autorefresh system with minimal resource usage? I have a script that clicks links how can i make it not click a certain. Such as how to make it dont click red link or dont click bold links. Code: var waiting_time = 30; var range_to = 15; var shuffle = function(o){ if(Math.floor(Math.random() * o.length) % 2) return o; for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); return o; }, isAds = function(o) { try { return o.href.match(/cks\.php\?k\=[0-9A-Fa-f]+\&cdk\=flase/) != null && o.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('div')[1].className == 'image' } catch(e) { return false } }, correctURL = function(r) { return window.location.href.match(r) != null }, setStatus = function(o, m) { o.parentNode.parentNode.parentNode.innerHTML = m }, addevent = function(o, f) { document.getElementById(o).addEventListener('click', f, false) }, byTag = function(t) { return document.getElementsByTagName(t) }, byName = function(n) { return document.getElementsByName(n) }, newTag = function(t) { return document.createElement(t) }, getwtime = function(o) { var i, a = o.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('div'); for(i = 0; i < a.length; i++) if(a[i].className == "counter") return a[i].innerHTML.match(/([0-9]+) seconds/)[1] }, strip = function(s) { var str = String(s).split("</td>").join("\r"), reg = /<td\s*width=['"]?100\%['"]?\s*>([^\r]+)\r/, match = str.match(reg), search = str.search(reg), out = [], i = 0, tmp; while(match) { str = str.substr(search + match[0].length, str.length); out[i] = match[1].replace(/\s*<script[^>]+>[\S\s]+<\/script>\s*/, ""); out[i] = out[i].replace(/<img[^>]+>/, ""); i++; match = str.match(reg); search = str.search(reg); }; return (out.length ? "<table><tr><td>"+out.join("</td><td>")+"</td></tr></table>" : "NO MATCH"); }, login = function() { var a = byTag("a"), I; for(I = 0; I < a.length; I++) if(a[I].href.match(/logout\.php/)) return true; return false }(), autosurf = false; if(correctURL(/\/ads\.php/)) { if(login) { var A = byTag("a"), i, html = "", timer, table = document.getElementById('content'), robot = newTag('div'), urls = [], current = 0, msg, tmr, load = function() { clearInterval(timer); timer = null; if(!urls[current]) { if(typeof autosurf == 'function') autosurf(); return }; var ajax = new XMLHttpRequest(); ajax.onreadystatechange = function() { try { if(ajax.readyState == 4) { if(ajax.status == 200) { if(String(ajax.responseText).match(/You have already viewed this advertisement/)) { msg.innerHTML = "Ads already opened, loading next ads..."; setStatus(urls[current], "OPENED"); current++; timer = setInterval(load, 1000) } else if(String(ajax.responseText).match(/Couldn't find an advertisement/)) { msg.innerHTML = "Ads expired, loading next ads..."; setStatus(urls[current], "EXPIRED"); current++; timer = setInterval(load, 1000) } else if(String(ajax.responseText).match(/You don't have permission to view this advertisement/)) { msg.innerHTML = "Forbidden Ads, loading next ads..."; setStatus(urls[current], "FORBIDDEN"); current++; timer = setInterval(load, 1000) } else { var j = urls[current].wtime, validate = function() { var ajx = new XMLHttpRequest(); ajx.onreadystatechange = function() { try { if(ajx.readyState == 4) { if(ajx.status == 200) { msg.innerHTML = "Ad click, opening next ads..."; setStatus(urls[current], "Ad Clicked & Confirmed"); current++; timer = setInterval(load, 1000) } else { msg.innerHTML = "Connection error, retrying..."; validate() } } } catch(e) { msg.innerHTML = "Validation error, retrying..."; validate() } }; msg.innerHTML = "Validating..."; ajx.open("GET", "cmp.php?complete&", true); ajx.send(null) }; tmr = setInterval(function() { if(j < 0) { validate(); clearInterval(tmr); tmr = null; return }; msg.innerHTML = "Ads loaded, waiting for "+j+" seconds..."; j-- }, 1000) } } else { msg.innerHTML = "Loading error, retrying..."; timer = setInterval(load, 1000) } } } catch(e) { msg.innerHTML = "Loading error, retrying..."; timer = setInterval(load, 1000) } }; msg.innerHTML = "Loading ads <b id='JFClickBot-current'>\""+(urls[current].parentNode.parentNode.parentNode.getElementsByTagName('a')[0].innerHTML)+"\"</b>...<br /><div id='JFClickBot-loading'></div>"; ajax.open("GET", urls[current].href, true); ajax.send(null) }; for(i = 0; i < A.length; i++) { try { if(isAds(A[i])) { urls[urls.length] = A[i]; urls[urls.length - 1].wtime = getwtime(A[i]) } } catch(e) {} }; robot.id = "JFClickBot-container"; robot.align = "center"; html = "<style>"; html += "#JFClickBot-container *{font-family:arial;color:black;font-weight:bold;text-decoration:none}"; html += "#JFClickBot-container{display:block}"; html += "#JFClickBot,#JFClickBot-title,#JFClickBot-container a.button{-moz-border-radius:3px;-webkit-border-radius:3px;-khtml-border-radius:3px;border-radius:3px;border: 1px solid #d91a2d}"; html += "#JFClickBot-container a.button{padding:10px;color:#000;background:#d91a2d}"; html += "#JFClickBot-container a.button:hover{color:#fff;background:#333}"; html += "#JFClickBot{padding:2px;display:block;width:900px;background:#fff;text-align:left}"; html += "#JFClickBot-title{display:block;padding:5px;background:#d91a2d;color:#fff}"; html += "#JFClickBot-msg{line-height:2em}"; html += "</style>"; html += "<div id='JFClickBot'><div id='JFClickBot-title'>JFClickBot For Gen4 Sites</div><br /><div id='JFClickBot-msg' align=center>"; html += "<b style='font-size:20px'>Warning</b><br />By Using This Tool You Agree to The Terms Of Use On <a href='http://clickbots.justfreebies.net' rel="nofollow" target='_blank'>ClickBots</a>.<br> We Are Not Resposible For Your Action, USE AT YOUR OWN RISK.<br><a href='http://clickbots.justfreebies.net' rel="nofollow" target='_blank'>© PTC ClickBots</a>"; html += "</div><br />"; html += "<center>"+(urls.length ? "<a href='javascript:;' class='button' id='adsclick'>Click All Ads ("+urls.length+")</a>" : "<a href='javascript:;' class='button'>No ads</a>")+" <a href='http://clickbots.justfreebies.net/features.php' class='button' rel="nofollow" target='_blank'>Features</a> <a href='http://clickbots.justfreebies.net/purchase.php' class='button' rel="nofollow" target='_blank'>Purcahse Site</a> <a href='http://clickbots.justfreebies.net/donate.php' class='button' rel="nofollow" target='_blank'>Donate</a></center><br />"; html += "</div></div>"; robot.innerHTML = html; table.parentNode.insertBefore(robot, table); msg = document.getElementById("JFClickBot-msg"); if(urls.length) { urls = shuffle(urls); addevent("adsclick", function(){ autosurf = function() { msg.innerHTML = "Done !"; alert(msg.innerHTML); }; this.parentNode.style.display = 'none'; timer = setInterval(load, 1000); }) }; addevent('silversurfer', function(){ alert("Sorry this features isnt available yet."); return; this.parentNode.style.display = 'none'; msg.innerHTML = "Auto surf mode activated..."; var adscontainer = newTag('div'); document.body.appendChild(adscontainer); adscontainer.style.display = 'none'; autosurf = function() { urls = []; current = 0; msg.innerHTML = "Reloading ads, finding new ads..."; var sec = Math.ceil(Math.random() * range_to * 60), j = sec, tm, ajx, reloadads = function() { msg.innerHTML = "Reloading ads, finding new ads..."; ajx = new XMLHttpRequest(); ajx.onreadystatechange = function() { try { if(ajx.readyState == 4) { if(ajx.status == 200) { msg.innerHTML = "Loaded, clearing codes and finding available ads..."; adscontainer.innerHTML = strip(ajx.responseText); A = adscontainer.getElementsByTagName('a'); for(i = 0; i < A.length; i++) { try { if(isAds(A[i])) urls[urls.length] = A[i] } catch(e) {} }; if(urls.length) { urls = shuffle(urls); msg.innerHTML = urls.length + " ads found"; timer = setInterval(load, 1000) } else { msg.innerHTML = "No ads found"; autosurf() } } else { msg.innerHTML = "Loading error, retrying..."; reloadads() } } } catch(e){ msg.innerHTML = "Loading error, retrying..."; reloadads() } }; ajx.open('GET', 'ads.php', true); ajx.send(null) }; tm = setInterval(function() { if(j < 0) { clearInterval(tm); tm = null; msg.innerHTML = "Time's up, reloading..."; reloadads() } else { msg.innerHTML = "Waiting for "+j+" seconds before reloading..."; j-- } }, 1000) }; if(urls.length) timer = setInterval(load, 1000) else autosurf() }) } } else if(correctURL(/\/register\.php/)) { var r = byName('6')[0], ref, cty, ori; if(r && force_referal_to) { ref = newTag('input'); ref.type = "hidden"; ref.name = "6"; ref.value = force_referal_to; r.form.insertBefore(ref, r.form.firstChild); r.name = "ref"; r.value = ""; cty = byName('7')[0]; ori = cty.value; cty.parentNode.removeChild(cty); r.form.getElementsByTagName('table')[0].rows[7].cells[1].innerHTML = "<input type=text name='7' value='"+ori+"' style='text-transform:uppercase' />" } } else if(correctURL(/\/forum/)) { try { var name = byName('a_name')[0], tr = newTag('tr'); name.parentNode.parentNode.parentNode.insertBefore(tr, name.parentNode.parentNode); tr.innerHTML = "<td>Username</td><td>:</td><td><input type=text name='a_name' value='"+name.value+"' style='width:100%'/></td>"; name.parentNode.removeChild(name) } catch(e) {} } i need a racing game in java graphics doesn't matter but speed should be good ?
Hi im making a calculator and there is a box that returns a fraction but i can only get the decimal here is what ive got so far: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html><head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>rivet calculator</title> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"></head><body> <p style="text-align: center;"> <a href="website.html"><img style="border: 0px solid ; width: 278px; height: 50px;" alt="" src="file:///Y:/TEMP/cody%20shoemake/old%20comp%20stuff/Documents/LOGO.png"></a><font size="+2"><span style="font-family: Century Gothic;"><font style="text-decoration: underline;" size="+3"><br> Rivet Calculator<span style="text-decoration: underline;"><span style="text-decoration: underline;"><span style="text-decoration: underline;"><span style="text-decoration: underline;"><span style="text-decoration: underline;"></span></span></span></span></span></font></span></font><br> </p> <font size="+2"><span style="font-family: Century Gothic;"><font style="text-decoration: underline;" size="+3"><span style="text-decoration: underline;"><span style="text-decoration: underline;"><span style="text-decoration: underline;"><span style="text-decoration: underline;"><span style="text-decoration: underline;"> </span></span></span></span></span></font></span></font> <div style="text-align: left;"><font size="+2"><span style="font-family: Century Gothic;"> </span></font> <script type="text/javascript"> // From: http://www.codingforums.com/showthread.php?p=857884#post857884 function RDcalc1() { // document.rc.ds.value="67"; // if (document.rc.ds.value=="67") { document.rc.rds.value=""; } // not a valid logical test -- what are you trying to do here??? document.rc.rds.value=''; } function RDcalc2() { document.rc.fd.value=document.rc.rds.value/32; document.rc.dd.value=(document.rc.rds.value/32).toFixed(2); document.rc.bl.value=(document.rc.rds.value/32*1.5).toFixed(2); document.rc.red.value=(document.rc.dd.value*2+1/16).toFixed(2); document.rc.med.value=(document.rc.dd.value*1.86).toFixed(2); document.rc.cdmed.value=(document.rc.dd.value*2).toFixed(2); } function RDcalc3() { document.rc.dn.value=((Number(document.rc.bl.value)+Number(document.rc.suv.value))/.0625).toFixed(2); document.rc.red.value=(document.rc.dd.value*2+1/16).toFixed(2); document.rc.med.value=(document.rc.dd.value*1.86).toFixed(2); document.rc.cdmed.value=(document.rc.dd.value*2).toFixed(2); document.rc.mrs.value=(document.rc.dd.value*4).toFixed(2); } </script> <form name="rc"> <table style="text-align: left; margin-left: auto; margin-right: auto;"> <tbody> <tr> <td> <br> </td> <td colspan="2" rowspan="1" style="text-align: left;"> Stack Up Value</td> </tr> <tr> <td style="vertical-align: top;"><br> </td> <td colspan="2" rowspan="1" style="vertical-align: top;"> <input name="suv" onkeyup="RDcalc3()" type="text"></td> </tr> <tr> <td style="vertical-align: top;"><br> </td> <td colspan="2" rowspan="1" style="vertical-align: top;"> Rivet Dash # <select name="rds" onchange="RDcalc1(this.value);RDcalc2();RDcalc3()"> <option onclick='document.rc.ds.value="67";document.rc.dsnd.value="0.0320"' selected="selected">1</option> <option onclick='document.rc.ds.value="51";document.rc.dsnd.value="0.0670"'>2</option> <option onclick='document.rc.ds.value="40";document.rc.dsnd.value="0.0980"'>3</option> <option onclick='document.rc.ds.value="30";document.rc.dsnd.value="0.1285"'>4</option> <option onclick='document.rc.ds.value="21";document.rc.dsnd.value="0.1590"'>5</option> <option onclick='document.rc.ds.value="11";document.rc.dsnd.value="0.1910"'>6</option> <option onclick='document.rc.ds.value="1";document.rc.dsnd.value="0.2280"'>7</option> <option onclick='document.rc.ds.value="F";document.rc.dsnd.value="0.2570"'>8</option> <option onclick='document.rc.ds.value="L";document.rc.dsnd.value="0.2900"'>9</option> <option onclick='document.rc.ds.value="O";document.rc.dsnd.value="0.3160"'>10</option> <option onclick='document.rc.ds.value="S";document.rc.dsnd.value="0.3480"'>11</option> <option onclick='document.rc.ds.value="V";document.rc.dsnd.value="0.3770"'>12</option> <option onclick='document.rc.ds.value="Z";document.rc.dsnd.value="0.4130"'>13</option> <option onclick='document.rc.ds.value="29/64";document.rc.dsnd.value="0.4531"'>14</option> </select> </td> </tr> <tr> <td colspan="3" rowspan="1" style="vertical-align: top;"> <hr style="width: 100%; height: 2px;"><br> </td> </tr> <tr> <td>Fraction Diameter</td> <td><input name="fd" readonly="readonly" type="text"></td><td>Buck Length <input name="bl" readonly="readonly" type="text"></td> </tr> <tr> <td>Decimal Diameter</td> <td><input name="dd" readonly="readonly" round_05up="" type="text"></td><td>Dash # <input name="dn" readonly="readonly" type="text"></td> </tr> <tr> <td>Drill Size</td> <td><input name="ds" readonly="readonly" type="text"></td><td>Recommended ED <input name="red" readonly="readonly" type="text readonly="></td> </tr> <tr> <td>Drill Size Nominal Diameter</td> <td><input name="dsnd" readonly="readonly" type="text"></td><td>Minimum ED <input name="med" input="" readonly="readonly" type="text"></td> </tr> <tr> </tr> <tr> <td>CSK/DIMPL E Minimum ED</td> <td><input name="cdmed" input="" readonly="readonly" type="text"></td><td>Multi-Row Spacing <input name="mrs" input="" readonly="readonly" type="text"></td> </tr> </tbody> </table> </form> <br> <font size="+2"><span style="font-family: Century Gothic;"></span></font></div> <font size="+2"><span style="font-family: Century Gothic;"><br> <br> <br> <br> </span></font> </body></html> Hi! frnds, I was wondering if you could help me with the JavaScript programing... Every possible help will be appreciated I am very new to the world of programming and JavaScript but I have some Ideas which I would like to execute and I will learn anything and everything in the way to accomplish them... Program: user end: the page is about users priorities and displaying back the selected... the program work as a user reaction based comparison module... where the priorities stored in the program are shown 2 at a time and lets user to select what is more important to him and stores the result in another variable than that variable is shown with another variable which is already stored and the result out of that is stored in another new variable and so on.. in the end it show the result of important selected priorities... 1) say there are 6 variables storing string values: Code: <script type = "text/javascript"> var p1 = "Doctors appointment"; var p2 = "studying for the exam"; var p3 = "Going out for most awaited shopping"; var p4 = "Login on Facebook"; var p5 = "Replying to text msgs"; var p6 = "Go out with friends"; 2) there are two sections on the html document: i) where the variables are displayed dynamically and changes the value on click.. it works like a comparison where user selects (onclick) what is more important to him shows the next value and so on... in the end stores the result... functioning(I have no I idea how to do this): say on the html document only two variables are displayed at first and than the user selects one of it as more important to him so the result is stored in another new variable than that new variable is shown with the third stored variable and once one of them is selected it is stored in another new variable and is compared with forth stored variable and so on till the last selected is stored as the result1... all comparisons must happen on the same div of the html document procedure has to loop three times till 3 results (result1, result2, result3) out of six are selected more important... result1 has to be removed from the next loop for result 2 as result1 is already selected important by the user.. result1 and result2 are to be removed from the next loop for result 3 as they are already selected important by the user ii) the second section displays important 3 results (result1, result2, result3) selected by him... my friend told jQuery can do the dynamic comparison part but I don't know how to use it... the logic of creating new variable for storing result and then comparing can be improved or changed... Please help Hello, Actually i know nothing about javascript. i have form and i need help to make javascript this is the form: </head> <SCRIPT language = "javascript"> function checkTotal() { function calculate() { A = parseFloat(document.form1.Qty.value); B = document.form1.selection.value; ---> 'please help i don't know the script command about onClick' and onChange combination' C = (A + B) * document.form1.total.value = C; } </SCRIPT> <body> <form name="form1" method="post" action=""> <table width="66%" border="0" id="form_table"> <caption> My Form </caption> <tr> <th width="41%"> <p>Qty ›</p></th> <td width="59%"><p> <input type="text" size="7" name="Qty"> <select name="selection" id="selection" onChange='Value'> <option value"1.00">Doll 1</option> <option value"2.00">Doll 2</option> <option value"3.00">Doll 3</option> <option value"4.00">Doll 4</option> </select> <br> Enter Qty and selection</p></td> </tr> <tr> <th>Merchandise ›</th> <td> <p> <input type="radio" name="None" value="0.00" onClick=""> None<br> <input type="radio" name="Key Chain 1" value="2.00" onClick=""checked> Key Chain 1<br> <input type="radio" name="Key Chain 2" value="3.00" onClick="" /> Key Chain 2</p></td> </tr> <tr> <th>Additional ›</th> <td><input type="checkbox" name="Story Book" value="4.00" onClick="" checked="checked" /> Story Book <br> <input type="checkbox" name="Mug" value="3.00" onClick="" /> Mug <br></td> </tr> <tr> <th>TOTAL›</th> <td><input type="text" style="background-color: #DCDDDD;" size="17" value="" name="Total" /></td> </tr> <tr> <th> </th> <td> <input type="submit" name="submit" value="Calculate" onClick = "javascript:calculate()"> <input type="reset" value="Reset"> </td> </tr> </table> </form> </body> </html> i need to get result from TOTAL checkout(input text) that sum from the value of options above (dropdown menu, checkbox, and radio button) multiplied by tax (4%) Coding master please help. Thank you very much. Greetings! I am currently working on my own company's website I am currently working with the FAQ page and I need to make a simple textbox, where visitors can type and ask a question and submit it, the question the visitor typed needs to be read by javascript from a seperate xml file which should be read with javascript. Now i dont know how to start with this and I would appreciate if someone could give me a lead on what things i should do and etc. Best regards Obs In my website i have many articles... URL of each article is like below http://www.mysite.com/article/1 http://www.mysite.com/article/2 http://www.mysite.com/article/3 http://www.mysite.com/article/4 Etc... So each article got a number in the URL >>>>> What I need now is <<<<<< To make little form with only 1 filed in main page Filed is to add the article number... Then by submitting the form the URL of article will open For example: If I enter number 4 and click submit That will open URL http://www.mysite.com/article/4 Thank you Hey everyone. I need a little help and I'm not an expert by any stretch of the imagination with javascript. I have a simple little code script and I'd like either the onClick function (or the entire code itself, whichever is easiest) to only load once every 24 hours for each IP address. So "123.1.22.333" should only get the effect of this code once every 24 hours regardless if they revisit my site 5 times a day let's say. So here's my little script: Code: <script language="JavaScript"> function goNewWin() { TheNewWin=window.open("http://google.com",'Google','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1'); TheNewWin.blur(); } </script> <body onClick="goNewWin()"> Any help would be very appreciated. Thanks! Hi, well earlier i asked for a script which can load game which showing some banner until the game is loading and the load progress that it shows, it shouldn't be fake, many people said you need flash for it, but atlast i found a script that can do that for me. BUT there is a issue when i started using the script in the script the width and height can be in px like width 500 but it can't be made to width 100% when i make it 100% the script stops working. I can't use px or any other thing except 100% as i want the flash to increase its width and height with the change in screen resolution. Here is the script, you can make a demo html file out of it for testing purposes, if you don't want to make one i am ready to provide a demo page too, please leave a comment for it. Thank you ^_^ Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Pre-roll Example page</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> <script type="text/javascript" src="http://files.cryoffalcon.com/woro/preroll.dev.js"></script> <style> .gamecontent {width:923px;padding:0px;margin:0px auto 0px auto;background-color:#FFF;} .gamecontent .gamewrapper {margin:0px auto 0px auto;} .gamecontent .game {float:left;margin:0px auto 0px auto;padding:0px;overflow:hidden;width:1px;height:1px} .gamecontent .ad {display:none;width:300px;height:300px;margin:0px auto 0px auto;padding:50px auto 0px auto;text-align:center;font-size:10px} .gamecontent .ad #progress {width:200px;height:10px;margin:10px auto 0px auto;padding:0px;border:solid 1px #E7B9D1;text-align:left;} .gamecontent .ad #pbar {width:0px;height:10px;background-color:#CCC;} .gamecontent .ad #pskip {text-align:center;} .medrectangle {width:300px;height:250px;border:none} </style> </head> <body> <div class="gamecontent"> <div class="gamewrapper" style="height:640px;width:640px;"> <div class="game" id="gameframe"></div> <div id="adframe" class="ad"> <div>Advertisement</div> <div id="plad"></div> <div id="progress"></div> </div> <noscript> <div> <!--Game embed code should be placed here here--> </div> </noscript> </div> </div> <script type="text/javascript" language="javascript"> var af = 'adframe'; var gf = 'gameframe'; var gid = 'gameswf'; var adinvoke = '<iframe class="medrectangle" src="<!--to show my logo or ad-->" scrolling="no"></iframe>'; function skipad() { $('#plad').html('<div></div>'); $('#'+af).hide(); $('#'+gf).css('width','640px'); $('#'+gf).css('height','640px'); } $('#gameframe').preloadad( { // calls the init method swf : 'http://games.balloontowerdefense.net/b/balloon_tower_defense_4_expansion.swf', width : 640, height : 640, gameid : gid, gameframe : gf, adframe : af, adcode : adinvoke, pltime : 10000, gametype : 'swf', base :'http://games.balloontowerdefense.net/b/', skiptxt : 'Click here to show the game', showad :'1' }); </script> </body> </html> in the above code the 640 width and height is the issue, as it doesn't work with 100% values, i was wondering how to make it work with 100% width and height. I don't know what did i miss or where did i go wrong? I heard that when we put javascript in website, then site takes time to open, is it correct ? If yes then which script is good for website.
How to make request "rtsp://localhost:554/sample_100kbit.mp4"? (in HTML5 or Javascript) I want to access video streaming data which source is present on Darwin server
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... Hello, I want to run video at our website at a specified time only,like i might want my video to be played at 9.00a.m exactly . how can i do it using javascript. Plz do revert back ASAP. Thanks, Revathi srikrishna I've just discovered (through trial and error) that if a variable is assigned a value without first being declared, it automatically has global scope, even if it is assigned inside a function. This is a pain in the butt because if you forget the var keyword, then suddenly ... whoops! You've got yourself a global variable! Is there any way that I can make javascript throw an exception if I fail to declare a variable before assigning a value to it? It would make things much easier, rather than having to hunt through increasingly complex functions to find that pesky unintentionally global variable. |