JavaScript - Mobile App Developers: Check Out My Code?
I am in a Mobile App Dev class. Our current project is to create a webapp that allows a user to search for zip,city,etc and get back weather and news.
I am having some issues in that my code is not working. Anyone have a moment to check it out? Quote: <!-- --> <!DOCTYPE html> <html lang="en-us"> <head> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" /> <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"></script> <script type="text/javascript" src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <script type="text/javascript"> function geo() { navigator.geolocation.getCurrentPosition(function(position) { do_something(position.coords.latitude, position.coords.longitude);}); } function top_stories(o) { var items = o.query.results.item; var output = ''; var no_items=items.length; for(var i=0;i<no_items;i++) { var title = items[i].title; var link = items[i].link; var desc = items[i].description; output += "<h3><a href='" + link + "'>"+title+"</a></h3>";// + desc + "<hr/>"; } // Place news stories in div tag document.getElementById('results').innerHTML = output; } function cb_weather(yql) { var temp = yql.query.results.channel.item.description; var region = yql.query.results.channel.location.city +", "+ yql.query.results.channel.location.region; document.write("<H3>"+ region +"</H3>" +temp); } function save(zipcode) { localStorage.zipcode = zipcode.value; alert("Zip code is " + localStorage.zipcode); } </script> <title>Mobile Local</title> </head> <body> <div data-role="page" id="menu"> <div data-role="header" data-theme="b"> <h1>Mobile Local</h1> <a data-role="button" class="ui-btn-left" onclick="geo();">Locate Me!</a> </div> <div data-role="fieldcontain" data-inline="true"> <label for="name">Enter your location:</label> <input type="text" name="zipcode" id="zipcode" value="" /> <a data-role="button" onclick="save(zipcode); return false;" value="Save Data" />Search</a> </div> <div data-role="content" id='weather'> <script id="weather" src='http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20location%3D02446&format=json&callback=cb_weathe r'></script> </div> <div data-role="content" id='results' onload="geo()"> <script src='http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20rss%20where%20url%20%3D%20"http%3A%2F%2Fnews.google.com%2Fnews%3Fgeo%3D024 46%26output%3Drss"&format=json&diagnostics=true&callback=top_stories'></script> </div> </div> </body> </html> Similar TutorialsMy question is about the following javascript function that converts 15 digit salesforce IDs to 18 digit salesforce IDs. The function was originally posted here. Developer 1 wrote the function: function convertToCaseInsensitiveId(id) { var hash = ''; for (var c = 0; c < 3; c++) { var h = 0; for (var i = 0; i < 5; i++) { var ch = id.charCodeAt(i + c * 5); if (ch >= 65 && ch <= 91) h += Math.pow(2, i); } hash += String.fromCharCode(h > 26 ? h + 48 - 26 : h + 65); } return id + hash; } Developer 2 said: Since the checksum numbers are mapped to AB..YZ012345, 25 gives Z. The following line > hash += String.fromCharCode(h > 26 ? h + 48 - 26 : h + 65); should be > hash += String.fromCharCode(h > 25 ? h + 48 - 26 : h + 65); otherwise 26 would be mapped to opening bracket (ASCII # 91). Which developer's solution is correct? I am trying to add values from 6 text boxes and display its sum automatically in 7th text box. This is not working. Please help. function calculate_a() { var a = document.getElementById('Para_A_A1_score').value ; var b = document.getElementById('Para_A_A2_score').value ; var c = document.getElementById('Para_A_A3_score').value ; var d = document.getElementById('Para_A_A4_score').value ; var e = document.getElementById('Para_A_A5_score').value ; var f = document.getElementById('Para_A_A6_score').value ; var g = (a+b+c+d+e+f) ; document.audit_billing_IE.product_name4.value = g ; } Quote: Below is the html form code that should automatically display the total value without clicking on any submit or send button <tr> <td> Parameter A </td> <td colspan='3'> <input type="text" name="product_name4" id="product_name4" onchange="calculate_a(this);" /> </td> </tr> Hi I am completely new to javascript, in fact just started loooking at it on w3 this week, anyhow thought I would do my first script. The script creates three random numbers between 1 and 10 but makes sure that they are completely different. It works, which is great as I have set out to achieve what was desired, however could somebody have a look and tell me if I have gone about it the right way. Code: <script type="text/javascript"> var one = (Math.floor(Math.random()*10+1)); document.write("1. " + one + "<br />"); do { var two = (Math.floor(Math.random()*10+1)); } while (two == one) document.write("2. " + two + "<br />"); do { var three = (Math.floor(Math.random()*10+1)); } while (three == two || three == one) document.write("3. " + three + "<br />" + "<br />"); </script> Thanks in advance. Joel I'll be the first to admit, I am not skilled with javascript, but I can do a little work here and there. I remember learning there is a way to detect a user's/viewer's browser. Is there a possible javascript that allows me to detect a viewer's browser, the based on the browser, selects css/html to use so that the website is viewed correctly?
Hi all, I am new to CodingForums.com as well as new to javascript. I am currently trying to create a small calculator for a friend which is to do with calculating a dose. The calculator itself works but I am now fine tweaking the text that appears with the calculated values. This is my code: Code: <script type="text/javascript"> function calculate() { var IBW = 1; var IBW2 = 1; var dose2 = 1; var CrCl = 1; var hgtft = document.getElementById("height_feet").value - 0; var hgtinches = document.getElementById("height_inches").value - 0; var weight = document.getElementById("weight").value - 0; var sex = document.getElementById("sex").value; var age = document.getElementById("age").value - 0; var creatinine = document.getElementById("creatinine").value - 0; if (age < 16) { alert("This tool is only for use in adult patients i.e. 16 years or older"); return; //process no further } if (sex == "M") { if (hgtft < 5) { IBW = 50; IBW2 = 50; } else { IBW = 50 + (2.3 * ((hgtft - 5) * 12 + hgtinches)); IBW2 = 50 + (2.3 * ((hgtft - 5) * 12 + hgtinches)); } if (IBW > weight) { IBW = weight } CrCl = ((140 - age) * IBW * 1.23) / creatinine; } else { if (hgtft < 5) { IBW = 45; IBW2 = 45; } else { IBW = 45 + (2.3 * ((hgtft - 5) * 12 + hgtinches)); IBW2 = 45 + (2.3 * ((hgtft - 5) * 12 + hgtinches)); } if (IBW > weight) { IBW = weight } CrCl = ((140 - age) * IBW * 1.04) / creatinine; } var dose = Math.round((5 * IBW) / 40.0) * 40.0 var IBW = Math.round(IBW, 1) var IBW2 = Math.round(IBW2,1) var CrCl = Math.round(CrCl, 0) if (CrCl < 40) { dose2 = "As GFR < 40mL/min Extended Interval Gentamicin is not indicated. Contact microbiology for an alternative agent"; } else { dose2 = dose "mg - Note: This dose has been calculated using a weight of " IBW "kg and rounded to the nearest 40mg to aid administration"; } document.getElementById('IBW2').innerHTML = IBW2 + "kg"; document.getElementById('CrCl').innerHTML = CrCl + "mL/min"; document.getElementById('dose2').innerHTML = dose2; } </script> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <table> <tr> <td>Height</td><td class="style17"><input id='height_feet' value=""/> feet</td><td><input id='height_inches' value=""/> inches</td> </tr> <tr> <td>Weight</td><td class="style17"><input id='weight' value=""/> kg</td> </tr> <tr> <td>Age</td><td class="style17"><input id='age'value=""/> years</td> </tr> <tr> <td>Creatinine</td><td class="style17"><input id='creatinine'/> mmol/L</td> </tr> <tr> <td>Sex</td><td class="style1"><select id='sex'> <option value="M">Male</option><option value="F">Female</option></select></td> </tr> </table><br /> <input type="button" onclick="calculate()" value="Calculate!"/><input id="Reset" type="reset" value="Reset" /> <br /> <br /> <br /> <br /> <table> <tr><td class="style16">Ideal Body Weight: </td><td id='IBW2' /></td></tr> <tr><td class="style16">Calculated GFR: </td><td id='CrCl' /></td></tr> <tr><td class="style16">Calculated Gentamicin Dose: </td><td id='dose2' /></td></tr> </table> What I am trying to do is have the dose displayed as: xxdose mg - Note: This dose has been calculated using a weight of IBWkg and rounded to the nearest 40mg to aid administration but if the CrCl is less than 40 then the dose message should be: As GFR < 40mL/min Extended Interval Gentamicin is not indicated. Contact microbiology for an alternative agent can anyone help me with this please? Hello, i wrote this code to open a page if doesn't exist a cookie but it doesn't open the page do you know where I wrong? 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> <title> HTML </title> </head> <body> <script type="text/javascript"> function CookieLeggi(CookieNome) { if (CookieNome.length==0) return null; var PosizioneIniziale = document.cookie.indexOf(CookieNome+"="); if (PosizioneIniziale == -1) return null; PosizioneIniziale += CookieNome.length+1; var PosizioneFinale = document.cookie.indexOf(";",PosizioneIniziale); if (PosizioneFinale == -1) PosizioneFinale = document.cookie.length; return unescape(document.cookie.substring(PosizioneIniziale,PosizioneFinale)); } function CookieScrivi(name,value,expiresUdM,expires,path,domain,secure) { if (!name || !value) { return false } if ((expiresUdM && expires) && (expiresUdM!='GMT')) { var ExpiresMillisec = ExpiresDate = Oggi = new Date(); switch (expiresUdM) { // calcola i JS-millisecondi del momento di scadenza case "anni": ExpiresMillisec=Oggi.getTime()+expires*365*24*60*60*1000; break; case "mesi": ExpiresMillisec=Oggi.getTime()+expires*31*24*60*60*1000; break; case "giorni": ExpiresMillisec=Oggi.getTime()+expires*24*60*60*1000; break; case "ore": ExpiresMillisec=Oggi.getTime()+expires*60*60*1000; break; case "minuti": ExpiresMillisec=Oggi.getTime()+expires*60*1000; break; case "secondi": ExpiresMillisec=Oggi.getTime()+expires*1000; break; default: ExpiresMillisec=Oggi.getTime()+expires; } ExpiresDate.setTime(ExpiresMillisec); expires = ExpiresDate.toGMTString(); } secure = (secure=="1" || secure==1 || secure=="secure") ? 1 : ""; document.cookie = name + "=" +escape(value) + ( (expiresUdM && expires) ? "; expires=" + expires : "") + ( (path) ? "; path=" + path : "") + ( (domain) ? "; domain=" + domain : "") + ( (secure) ? "; secure" : ""); if (CookieLeggi(name)==null && secure!=1) { return false; } else { return true; } } </script> <script type="text/javascript"> if (CookieLeggi(liveads) == "null") { window.open("http://www.google.com", "Google"); CookieScrivi(liveads, adsm, ore, 12, /, .localhost, 1); } else { break; } </script> </body> </html> Hello, I need help. I'm testing aps.net controls. I have add Repeater with some content. Repeater is inside of Panel which has Vertical ScrollBars. Timer1 is updating Repeater. As I need scrollbar on PageLoad on the bottom of Panel control, I have add javascript. But, now problem is each time when try to move scrollbar up, Timer push it down. But, I would like somehow to keep in position if move it. I have try it with javascript code OnMouseOver with _StopTimer, but it effect only when mouse is over asp.net cotrol, not it's scrollbar. Any idea? Note: I have been Googling, Yahooing many ours, and try different codes, but none was working. So, really need some new approach. Note: MaintainScrollPositionOnPostback="true" is already added on page. Thank you in advance for help. Code: <asp:ScriptManager ID="ScriptManager1" runat="server"/> <script type="text/javascript"> if (Sys != null) { var instance = Sys.WebForms.PageRequestManager.getInstance(); if (instance != null) { instance.add_endRequest(function (sender, args) { SetScroll() }); } } function pageLoad() { window.onload = SetScroll; } function SetScroll() { var objDiv = document.getElementById("<%=Panel1.ClientID%>"); objDiv.scrollTop = objDiv.scrollHeight; } </script> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label> <asp:Timer ID="Timer1" runat="server" Interval="1000"> </asp:Timer> </ContentTemplate> </asp:UpdatePanel> <asp:Panel ID="Panel1" runat="server" ScrollBars="Auto" Height="193px" Width="467px" BorderColor="#66CCFF" BorderStyle="Solid" BorderWidth="1px"> <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <div style="font-family: calibri; color: #000099;"> TEST </BR> TEST </BR> TEST </BR> TEST </BR> TEST </BR> TEST </BR> TEST </BR> TEST </BR> TEST </BR> </asp:Repeater> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> </Triggers> </asp:UpdatePanel> </asp:Panel> I am very new to coding, trying to teach myself some javascript. I know this is a very simple code, I just can't seem to nail down what is going wrong. Feeling really stupid right now. Heres the code: Code: <html> <head> <script language="JavaScript"> var choice=confirm("Press ok for black. Press cancel for red."); if (choice==true){ document.bgColor="yellow"; document.fgColor="black"; } else { document.bgColor="red"; document.fgColor="white"; } </script> <body> <p>words</p> </body> </html> If someone could take a second to set me straight, I would really appreciate it. btw: hope I posted all this according to the "rules". I tried On this webpage http://www.corkdiscos.com/testimonials.html i have a like button. when a user clicks like a comment box appears. when i unlike the button the comment box disappears this is ok but when a user has already liked the facebook page and comes to my webpage the comment box does not show. so im looking for a piece of javascript to check if a user has like the button on my page and if so to show the comment box. please check my source code of the website http://www.corkdiscos.com/testimonials.html to see what i have so far. any help would be greatly appreciated Similiar to that of CBS.com or AOL.com when you visit them on the iphone. Something that responds to the swipe gesture within the iphone. I've been searching google, but mobile web resourses are far and few. Also tried to check out their source and it only shows it as one long line of text, not ideal for trying to read code. Hey, I'm working on a mobile website and need some help with my mobile browser detection script. I have it working for iPhone, iPod Touch, and Windows Mobile Devices. I need help getting it to detect for Blackberry Browser (Blackberry Devices), Blazer Browser (Palm Devices), Opera Mini Browser, Opera Mobile Browser, and other mobile browsers if possible. Does anyone know how to modify (and test if you have a phone to test with, as I don't have all of these devices) this javascript?: Code: if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {location.replace("mobile.html");} if((navigator.appVersion.indexOf("Windows CE")>0)) {location.replace("mobile.html");} Thanks for your help! -Chris I want to disable modal box when the page it is attached to is being viewed on a mobile device. I have tried what I know and have crashed and burned. Help will be greatly appreciated. This is the code that I have use... Code: <script src="/o/4055/images/jquery.avgrund.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $(".hidden").avgrund({ width: 500, // max is 640px height: 340, // max is 350px showClose: true, // switch to 'true' for enabling close button showCloseText: 'close', // type your text for close button closeByEscape: false, // enables closing popup by 'Esc'.. closeByDocument: true, // ..and by clicking document itself enableStackAnimation: false, // another animation type onBlurContainer: 'div#container', // enables blur filter for specified block template: '<div style="margin: 0 auto; padding:0; width:500px; height:350px;">' + '<a href="https://afl.salsalabs.com/o/4055/p/salsa/donation/common/public/?donate_page_KEY=7606" style="border:none;" target="_blank"><img src="http://i1298.photobucket.com/albums/ag60/ProdSolutions/Lightbox_1_zpscead0a26.jpg" width="500px" height="350px" /></a>' + '</div>', onUnload: function() { var date = new Date(); date.setTime(date.getTime() + (1 * 24 * 60 * 60 * 1000)); $.cookie("ARA_October_2014","true",{path:"/",expires:date}); } }); $(".hidden").trigger('click'); }); $("#submitContribution").attr('value', 'Donate Now'); $("label[for=cc_number]").after($('div#useCC fieldset#credit_card_information div.formRow div.helpText')); $("#credit_card_information > div:nth-child(6) > label:nth-child(1) > a:nth-child(1)").before($('#CVV2')); $('#personal_information > legend:nth-child(1)').each(function() { var text = $(this).text(); $(this).text(text.replace('Your Information', 'Your Billing Information')); }); $('div.formRow:nth-child(19) > label:nth-child(1)').each(function() { var text = $(this).text(); $(this).text(text.replace('Phone', 'Your Phone')); }); $('#credit_card_information legend').each(function() { var text = $(this).text(); $(this).text(text.replace('Credit Card Information', 'Payment Information')); }); $('#credit_card_information > div:nth-child(3) > label:nth-child(1)').each(function() { var text = $(this).text(); $(this).text(text.replace('Card Number', 'Credit Card Number')); }); $('#submit > p:nth-child(2)').each(function() { var text = $(this).text(); $(this).text(text.replace('Please click the submit button only once.', 'Please click this button only once.')); }); $('.readMore').click(function(){ $('.readMore').hide('slow'); $('.text2').show('slow'); }); </script> I'm trying to create a mobile app for an internet station, and right now I'm just trying to get how to get it to play. I've got it to connect to an MP3 file and it works just like I want it to. However, upon setting it to connect to the stream, it returns with "java.io.IOException: failed to connect to http://71.127.84.92:8004 : response does not start with HTTP it starts with: ICY" Here is the code: Code: public void commandAction(Command command, Displayable displayable) { if (command == stopButton){ if (isPlaying == true) { try { Remedy.stop(); Remedy.close(); } catch (MediaException pe) {System.out.println(pe); } finally { isPlaying = false; mMainForm.removeCommand(stopButton); mMainForm.addCommand(playButton); } } } else if (command == playButton) { try { Remedy = Manager.createPlayer("http://71.127.84.92:8004"); //This is the URL causing the error Remedy.start(); System.out.println("Done"); } catch (MediaException pe) { System.out.println(pe); } catch (java.io.IOException ioe) { System.out.println(ioe); } finally { isPlaying = true; mMainForm.removeCommand(playButton); mMainForm.addCommand(stopButton); } } else { System.out.println("Exiting..."); notifyDestroyed(); } } Can anyone help me get it to play the shoutcast stream? Any help would be greatly appreciated, I am a Java noob. Im working on a mobile site for a friend and im curious, can i trigger javascript events on screen flick (By flick i mean the way to scroll through homepage screens). Id love to run a few things like that but i dont know if thats possible. If it is is there a tutorial about i could look at?
Is there a way that we can Disable Panning in Fennec, or Mobile Chrome (on android devices). The Panning, and inertial scrolling effects that are part of the browser are interfering with being able to get the mouse position. I would like to use DHTML paint on my Google Android MID.... i really have no idea where to start.. I am making a site HERE and I was using this: Code: <script> if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile/i.test(navigator.userAgent)) { if (document.URL != "http://www.precisionpaintandcollision.net") { window.location = "http://m.precisionpaintandcollision.net"; } } </script> to auto-redirect mobile users to the mobile site and I want to keep that but I want them to be able to view the desktop site without that code affecting them. I know some apps have "force/request desktop site" but i'd like them to be able to just view the desktop site without auto redirecting to mobile site. Is this possible? Thanks -John Hi, everyone! I am a freshman in the JavaScript area. One thing i am wondering recently is that whether JavaScript can get a data from the sensors as accelerometer, gyroscope or orientation sensors of a mobile device? From as a iPhone, iPad or some other Android system mobile phones, may i just use JavaScript to get the data from their sensors? Looking forward the replies from anybody. Thanks a lot! Best regards, Borui http://mybestmaterial.blueeyedpandahosting.com/cep/1/ Works exactly as expected (and all the code is built into the source code view of the page.) What happens is 2 timers are set up. 1 is running when user clicks the Start/Stop link. The second is started when the user clicks the Laughter Start/Stop link. So the sequence should be User -- Start click then after that -- laughter-start-stop click... You will see both timers start running. The laughter click will be clicked multiple times as the app is designed to time how much laughter a comedian or speaker is getting relative to the amount of time on stage. So click the laughter start stop multiple times before clicking the START-STOP the last time. Then a PAR score is generated - which is a simple percent of the time laughter happened, vs the time on stage. The link above works like a charm. THE PROBLEM is -- on my SPRINT TREO 700p --- when I click the laughter start/stop click it stops all the timers. I think for some reason the TREO won't allow the second NEW DATE() to be declared or something... because when I comment those two lines out --- line 166 and 167 in Dreamweaver version of the file -- (if you copy full source into dreamweaver...) Then the clicking doesnt' stop the main timer -- but it also doesn't work!! ANY THOUGHTS on how to decloare the SCOPE fo the NEW DATE() so it only effects that one function? OR any other suggestions? Code pasted below 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=ISO-8859-1" /> <title>Comedy Analyzer - Simple</title> </head> <script type="text/javascript"> var flagclock = 0; var flagstop = 0; var stoptime = 0; var currenttime; var splitdate = ''; var output; var clock; function startstop() { //var startstop = document.getElementById('startstopbutton'); var startdate = new Date(); var starttime = startdate.getTime(); if(flagclock==0) { flagclock = 1; counter(starttime); } else { if(laughter_flagclock==1) { laughter_startstop(); } flagclock = 0; flagstop = 1; splitdate = ''; //total laughter === running_total_laughter_time; //total time == running_total_time; var par_score = (Math.round(running_total_laughter_time/running_total_time*100))/100; var par_score_percent = par_score*100; //var par_score = running_total_laughter_time/running_total_time; laughter_output.value = "PAR SCORE = " + par_score_percent; } } var running_total_time; function counter(starttime) { output = document.getElementById('output'); clock = document.getElementById('clock'); laughter_output = document.getElementById('laughter_output'); currenttime = new Date(); var timediff = currenttime.getTime() - starttime; if(flagstop == 1) { timediff = timediff + stoptime } if(flagclock == 1) { clock.value = formattime(timediff,''); running_total_time = timediff; refresh = setTimeout('counter(' + starttime + ');',10); } else { //start and stop the running counter while adding the values to the next deal. window.clearTimeout(refresh); stoptime = timediff; } } function formattime(rawtime,roundtype) { if(roundtype == 'round') { var ds = Math.round(rawtime/100) + ''; } else { var ds = Math.floor(rawtime/100) + ''; } var sec = Math.floor(rawtime/1000); var min = Math.floor(rawtime/60000); ds = ds.charAt(ds.length - 1); if(min >= 60) { startstop(); } sec = sec - 60 * min + ''; if(sec.charAt(sec.length - 2) != '') { sec = sec.charAt(sec.length - 2) + sec.charAt(sec.length - 1); } else { sec = 0 + sec.charAt(sec.length - 1); } min = min + ''; if(min.charAt(min.length - 2) != '') { min = min.charAt(min.length - 2)+min.charAt(min.length - 1); } else { min = 0 + min.charAt(min.length - 1); } return min + ':' + sec + ':' + ds; } function resetclock() { if(flagclock == 1) { //alert("if side of reset clock"); var resetdate = new Date(); var resettime = resetdate.getTime(); counter(resettime); } else { //alert("ELSE side of reset clock"); clock.value = "00:00:0"; } flagstop = 0; stoptime = 0; splitdate = ''; laughter_resetclock(); window.clearTimeout(refresh); output.value = ''; } </script> <script type="text/javascript"> var laughter_flagclock = 0; var laughter_flagstop = 0; var laughter_stoptime = 0; var laughter_currenttime; var laughter_splitdate = ''; var laughter_output; var laughter_clock; var count = 0; function laughter_startstop() { var laughter_startdate = new Date(); var laughter_starttime = laughter_startdate.getTime(); if(laughter_flagclock==0) { laughter_flagclock = 1; laughter_counter(laughter_starttime); laughter_number_text = document.getElementById('laughter_number'); count++; laughter_number_text.value = count; } else { laughter_flagclock = 0; laughter_flagstop = 1; laughter_splitdate = ''; } } var running_total_laughter_time; function laughter_counter(laughter_starttime) { laughter_clock = document.getElementById('laughter_clock'); laughter_currenttime = new Date(); var laughter_timediff = laughter_currenttime.getTime() - laughter_starttime; if(laughter_flagstop == 1) { laughter_timediff = laughter_timediff + laughter_stoptime } if(laughter_flagclock == 1) { laughter_clock.value = laughter_formattime(laughter_timediff,''); running_total_laughter_time = laughter_timediff; //laughter_output.value += "-- laughter -- "+running_total_laughter_time; laughter_refresh = setTimeout('laughter_counter(' + laughter_starttime + ');',10); } else { window.clearTimeout(laughter_refresh); laughter_stoptime = laughter_timediff; } } function laughter_formattime(laughter_rawtime,laughter_roundtype) { if(laughter_roundtype == 'round') { var laughter_ds = Math.round(laughter_rawtime/100) + ''; } else { var laughter_ds = Math.floor(laughter_rawtime/100) + ''; } var laughter_sec = Math.floor(laughter_rawtime/1000); var laughter_min = Math.floor(laughter_rawtime/60000); laughter_ds = laughter_ds.charAt(laughter_ds.length - 1); if(laughter_min >= 60) { laughter_startstop(); } laughter_sec = laughter_sec - 60 * laughter_min + ''; if(laughter_sec.charAt(laughter_sec.length - 2) != '') { laughter_sec = laughter_sec.charAt(laughter_sec.length - 2) + laughter_sec.charAt(laughter_sec.length - 1); } else { laughter_sec = 0 + laughter_sec.charAt(laughter_sec.length - 1); } laughter_min = laughter_min + ''; if(laughter_min.charAt(laughter_min.length - 2) != '') { laughter_min = laughter_min.charAt(laughter_min.length - 2)+laughter_min.charAt(laughter_min.length - 1); } else { laughter_min = 0 + laughter_min.charAt(laughter_min.length - 1); } return laughter_min + ':' + laughter_sec + ':' + laughter_ds; } function laughter_resetclock() { //alert("laughter_resetclock called"); if(laughter_flagclock == 1) { var laughter_resetdate = new Date(); var laughter_resettime = laughter_resetdate.getTime(); laughter_counter(laughter_resettime); } else { laughter_clock.value = "00:00:0"; } laughter_flagstop = 0; laughter_stoptime = 0; laughter_splitdate = ''; count = 0; laughter_number_text.value = count; window.clearTimeout(refresh); laughter_output.value = ''; //window.clearTimeout(refresh); output.value = ''; } </script> <body> Running Time :: <input id="clock" type="text" value="00:00:0" style="text-align: center;" size="14"readonly><br /> Laughter Time :: <input id="laughter_clock" type="text" value="00:00:0" style="text-align: center;"size="14" readonly><br /> Laugh Count :: <input id="laughter_number" type="text" value="0" style="text-align: center;" size="4" readonly><br /> <div id="start_button"><a href="javascript:startstop();">Timing Start/Stop</a></div> <div id="laughter_start_button"><a href="javascript:laughter_startstop();">Laughter Start/Stop</a></div> <textarea id="laughter_output" style="height: 90%;" cols="40" rows="1"></textarea><br /> <a href="javascript:resetclock();">Full-Reset</a><br /><br /> </body> </html> Hi guys. I'm working a bunch of pre existing code on a CMS. Just after a quick fix. Doing a show/hide thing on a particular div somewhere on the page depending if a checkbox is ticked or not. Currently there is 3 checkboxes that are dynamically added through the CMS. Here's simplified version of the form: Code: <form id="simplesearch" name="simplesearch"> <input type="checkbox" onclick='showhidefield(this.value)' name="meta_data_array_search_criteria[custom_profile_type][]" value="5" class="input-checkboxes" /> <input type="checkbox" onclick='showhidefield(this.value)' name="meta_data_array_search_criteria[custom_profile_type][]" value="4" class="input-checkboxes" /> </form> And here's the javascript I was playing with. Code: function showhidefield(id) { if(document.simplesearch.meta_data_array_search_criteria[custom_profile_type][''].checked) { document.getElementById("profile_fields_wrapper_" + id).style.visibility = "visible"; } else { document.getElementById("profile_fields_wrapper_" + id).style.visibility = "hidden"; } } Problem I'm having is how do i do a check to see if those checkboxes are checked in the javascript with those name arrays? How do i separate them? 'm guessing I have to loop through them or something?Hopefully that make senses - it's late here and I'm losing the plot Any pointers would be gratefully welcomed |