JavaScript - How To Extend A Script With Extra Vars To Check?
Hello all,
Sorry for not reading the "posting guidelines" earlier. I understand that you guys are not reading/loading complete codes, my bad. Let me try again. This is a code for checking numbers A1 -> B1, when there is a match, the code will be green, otherwise black. Can somebody explain to me how I can extend this script, that more then one array is checked?? Code: <script type = "text/javascript"> var a1 = ["2","5", "11","16","23","45", "46"]; var b1 = ["2","3","8","12","23", "37", "41", "45", "48"] for (var i = 0; i< a1.length; i++) { for (var j = 0; j< b1.length; j++) { if (a1[i] == b1[j]) { a1[i]= "g"+ a1[i]; } } } for (var i = 0; i< a1.length; i++) { if (a1[i].substr(0,1) == "g") { a1[i] = a1[i].substr(1,20); document.write("<font color = 'green'>", a1[i] + "    "); } else { document.write("<font color = 'black'>", a1[i] + "    "); } } document.write("<br><br>"); for (var j = 0; j< b1.length; j++) { document.write("<font color = 'black'>", b1[j] + "    "); } </script> Thanks a ton in advance Similar Tutorialsplz check bold part of function is not working. what is wrong with it.? Code: function onesizecheck(chk_id,siz) { alert(chk_id); if(document.getElementById('siz_check').value=='') { document.getElementById('siz_check').value=siz; }//end if if(document.getElementById('siz_check').value==siz) { document.getElementById('siz_check').value=siz; } else { alert('Multi size are not allowed.'); for(var i = 0; i < document.delet['checkbox[]'].length; i++){ var cb = document.getElementById('checkbox'); alert(cb[i].value); } } }//end function Hi all I have this rollover script (original done by Old Pedant) which I have modified making it 5 sets of 2 images. Althogh it seems to work I have a feeling it's not the best way of doing it hahahaha It seems clumsy to me (and i'm no coder hahaaha) Could it be made more concise. (or just made correct) Would really appreciate any help or positive comments. Code: <script type="text/javascript"> function linkOver(link) { var image = link.getElementsByTagName("IMG")[0]; image.src = image.src.replace("Off_1.png","On_1.png"); image.src = image.src.replace("Off_2.png","On_2.png"); image.src = image.src.replace("Off_3.png","On_3.png"); image.src = image.src.replace("Off_4.png","On_4.png"); image.src = image.src.replace("Off_5.png","On_5.png"); } function linkOut(link) { var image = link.getElementsByTagName("IMG")[0]; image.src = image.src.replace("On_1.png","Off_1.png"); image.src = image.src.replace("On_2.png","Off_2.png"); image.src = image.src.replace("On_3.png","Off_3.png"); image.src = image.src.replace("On_4.png","Off_4.png"); image.src = image.src.replace("On_5.png","Off_5.png"); } </script> </head> I have 5 of these: Code: <body> <div id="megaanchor" onmouseover="linkOver(this), callSecondFunction('soldier',50,40,200);" onmouseout="linkOut(this);" ><img src="images/image_Off.png" alt="" border="0" /> </body> Hi all, I am writing an administration panel for a web site. I want to check if the client's browser javascript enabled and if it is not enabled, a warning DIV comes telling the client to enable javascript and disable the actual page (make the actual page non-usable). Is there a way to do that? Thanks in advance telmessos I have a two fold question: 1) Why would my while statement not be working I have cleaned up my code a little (although not perfect) but my while statement is not behaving, it does not output any numbers on a console.debug (using google chrome, or any other browser for that matter) which from my understanding it should? and 2) Slightly out of the remit of this forum I suppose, but this code is quite lengthy and I know there are ways to make this more efficient I just dont know what they are? Code: function generatePurchaseFields(dom) { new Ajax.Request('/control/?page=tldmaxyears&domain=' + dom, { method: 'get', asynchronous: false, onSuccess: function(transport) { window.maxyears = transport.headerJSON.years.maxterm; window.minyears = transport.headerJSON.years.minterm; } }); var maxyears = window.maxyears; var minyears = window.minyears; //console.debug(minyears + maxyears); var currentyear = minyears; while (currentyear <= maxyears) { console.debug(window.currentyear); console.debug(window.maxyears); if (currentyear == 1) { var surfix = ' Year'; } else { var surfix = ' Years'; } rows += '<option value="' + currentyear + '">' + currentyear + surfix + '</option>'; currentyear++; } var fields = '<input type="checkbox" value="' + dom + '" name="domain[]" />' + '<select name="years">' + '<option value="1">1 Year</option>' + rows + '</select>'; console.debug(rows); return fields; } Kind thanks for any help you may be able to provide. Thanks PodMan99 Question: if I declare a variable in on js fiile, is this available to another js file that is loaded? Answer: yes, it's available (unless inside of a function or something) BUT: does it matter WHERE I declare this variable?? Let's say, I have the following in my HTML file: <script src="script/main.js"></script> And then at the very bottom of my HTML page before the </body> tag I have: <script type="text/javascript">var myvariable = "Sample Data";</script> So, is myvariable available to main.js? In simple tests I've done, yes it does seem to be available But... what if I have a lot of other js code running in between Does this change anything? Thanks OM The problem stems from Internet Explorer's inability to expand questions in the FAQ section of my website ( link: http://phonesforyourcharity.com/faq.php ). Of course the expand function works in Firefox and Safari. The <script type="text/javascript" src="js/faq.js"></script> in the source refers to: PHP Code: $(function(){ $("dd.answer") .hide(); $("dl.faq dt") .append("<br /><a href='#' title='Reveal Answer' class='answer-tab'>Answer</a>"); $(".answer-tab") .click(function(){ $(this) .parent().parent() .find("dd.answer") .slideToggle(); return false; }); }); If i have 4 vars var one = 29.1 var two = 5.4 var three = 12.4 var four = 15 how can compare all 4 and find the smallest? in this case the result would be two Hi, I'm wondering if it's possible to set a variable to send through with my form using the confirm alert box. Please let me know. Much appreciated. [CODE] <html> <head> <script type="text/javascript"> <!-- function confirmation() { var answer = confirm("Would you like to stay logged into the website? Click OK to stay logged in for your next visit or CANCEL so your login won\'t be remembered.") if (answer){ //how do I set this to rememberMe=1 } else{ //how do I set this to rememberMe=0 } } //--> </script> </head> <body> <form action="test-alert2.cfm" method="post"> <input type="hidden" name="rememberMe" value="rememberMe"> <input type="submit" onClick="confirmation()" value="Login" /> </form> </body> </html> [CODE] Hello, I have a bit of javascript that is supposed to change picture and its accompanying text when you hover over a bit of link text in another area of the page. This is working, however, the text is toggling without the picture due to an invisible area next to each link. I am not sure if it's an issue with applying my javascript to another bit of code or what. Here is the code that I have that flips the text: Code: <script type="text/javascript"> function tabOver(which) { for ( var d = 1; d <= 31; ++d ) { document.getElementById("TAB"+d).style.display = ( d == which ) ? "block" : "none"; } } </script> and here is the bit that flips the pics: Code: <script> function changeimage(towhat,url){ if (document.images){ document.images.targetimage.src=towhat.src gotolink=url } } function warp(){ window.location=gotolink } </script> <script language="JavaScript1.1"> var myimages=new Array() var gotolink="#" function preloadimages(){ for (i=0;i<preloadimages.arguments.length;i++){ myimages[i]=new Image() myimages[i].src=preloadimages.arguments[i] } } preloadimages("photos/aes1.jpg","photos/aes2.jpg","photos/aes3.jpg","photos/aes4.jpg","photos/aes5.jpg") </script> And here is the html where they show up: Code: <div id="mainimg-staff"><a href="javascript:warp()"><img src="img/select-aes.gif" name="targetimage" border=0></a> <div id="TABHOLDER"> <div id="TAB1" class="tabbed" style="display: block;"> </div> <div id="TAB2" class="tabbed"> <h1>Cheryl Lyon</h1> <ul> <li> Basic facials and skin treatments <li> Waxing <li> Specializing in naturopathic facial treatments </ul> </div> <div id="TAB3" class="tabbed"> <h1>Jackie T.</h1> <ul> <li> 10+ years experience <li> Facials and skin treatments <li> Waxing <li> Specializing in <em>Extreme</em> eyelash extensions </ul> </div> (there are a lot more text bits but I only included 2 to keep this short) Finally, here is the link that is making all this wonderful stuff happen: Code: <div style="left: 100px;" onmouseover="tabOver(2);"><a href="staff-aes.shtml" onMouseover="changeimage(myimages[0],this.href)">Cheryl Lyon</a></div> Do you see how I combined the pic and text in one code? I promise you that it is on accident that this is working at all. Could this be a style issue and not a javascript issue? I can't find anything in my css that will fix this. 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 hello there this is in vb script. but i dont where to post it. can any one hlep me out plzz I need to check if the date entered by user is within 5th date from current date. I am trying to do it this way entered date has month and date value Code: sResvDate = 01/24 Set sMaxDays to getdate(5) but get date will give year too. and how do i compare if it less than 5th day or not. 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 I have a webpage which has the prototype library in it as well as my own script. I just started on it, but I've already run into issues using the for... in loop. I'll admit, I'm a complete noob at javascript, so this is probably something pretty simple. Code: function prepareToolBar() { //define toolbar tool names var toolbar = [ 'line', 'circle', 'ellipse', 'square', 'rectangle', 'text']; for (var i in toolbar) { var tmp = document.createElement("p"); tmp.appendChild(document.createTextNode(toolbar[i])); document.body.appendChild(tmp); } } addLoadEvent(prepareToolBar); function addLoadEvent(func) { var oldonload = window.onload; if (typeof oldonload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } } Below is the output on the page from the function: Code: circle ellipse square rectangle text function (iterator, context) { var index = 0; iterator = iterator.bind(context); try { this._each(function (value) {iterator(value, index++);}); } catch (e) { if (e != $break) { throw e; } } return this; } function (number, iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var index = - number, slices = [], array = this.toArray(); while ((index += number) < array.length) { slices.push(array.slice(index, index + number)); } return slices.collect(iterator, context); } function (iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var result = true; this.each(function (value, index) {result = result && !!iterator(value, index);if (!result) {throw $break;}}); return result; } function (iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var result = false; this.each(function (value, index) {if ((result = !!iterator(value, index))) {throw $break;}}); return result; } function (iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var results = []; this.each(function (value, index) {results.push(iterator(value, index));}); return results; } function (iterator, context) { iterator = iterator.bind(context); var result; this.each(function (value, index) {if (iterator(value, index)) {result = value;throw $break;}}); return result; } function (iterator, context) { iterator = iterator.bind(context); var results = []; this.each(function (value, index) {if (iterator(value, index)) {results.push(value);}}); return results; } function (filter, iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var results = []; if (Object.isString(filter)) { filter = new RegExp(filter); } this.each(function (value, index) {if (filter.match(value)) {results.push(iterator(value, index));}}); return results; } function (object) { if (Object.isFunction(this.indexOf)) { if (this.indexOf(object) != -1) { return true; } } var found = false; this.each(function (value) {if (value == object) {found = true;throw $break;}}); return found; } function (number, fillWith) { fillWith = Object.isUndefined(fillWith) ? null : fillWith; return this.eachSlice(number, function (slice) {while (slice.length < number) {slice.push(fillWith);}return slice;}); } function (memo, iterator, context) { iterator = iterator.bind(context); this.each(function (value, index) {memo = iterator(memo, value, index);}); return memo; } function (method) { var args = $A(arguments).slice(1); return this.map(function (value) {return value[method].apply(value, args);}); } function (iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var result; this.each(function (value, index) {value = iterator(value, index);if (result == null || value >= result) {result = value;}}); return result; } function (iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var result; this.each(function (value, index) {value = iterator(value, index);if (result == null || value < result) {result = value;}}); return result; } function (iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var trues = [], falses = []; this.each(function (value, index) {(iterator(value, index) ? trues : falses).push(value);}); return [trues, falses]; } function (property) { var results = []; this.each(function (value) {results.push(value[property]);}); return results; } function (iterator, context) { iterator = iterator.bind(context); var results = []; this.each(function (value, index) {if (!iterator(value, index)) {results.push(value);}}); return results; } function (iterator, context) { iterator = iterator.bind(context); return this.map(function (value, index) {return {value: value, criteria: iterator(value, index)};}).sort(function (left, right) {var a = left.criteria, b = right.criteria;return a < b ? -1 : a > b ? 1 : 0;}).pluck("value"); } function () { return [].concat(this); } function () { var iterator = Prototype.K, args = $A(arguments); if (Object.isFunction(args.last())) { iterator = args.pop(); } var collections = [this].concat(args).map($A); return this.map(function (value, index) {return iterator(collections.pluck(index));}); } function () { return this.length; } function () { return "[" + this.map(Object.inspect).join(", ") + "]"; } function (iterator, context) { iterator = iterator.bind(context); var result; this.each(function (value, index) {if (iterator(value, index)) {result = value;throw $break;}}); return result; } function (iterator, context) { iterator = iterator.bind(context); var results = []; this.each(function (value, index) {if (iterator(value, index)) {results.push(value);}}); return results; } function (object) { if (Object.isFunction(this.indexOf)) { if (this.indexOf(object) != -1) { return true; } } var found = false; this.each(function (value) {if (value == object) {found = true;throw $break;}}); return found; } function () { return this.map(); } function reverse() { [native code] } function forEach() { [native code] } function () { this.length = 0; return this; } function () { return this[0]; } function () { return this[this.length - 1]; } function () { return this.select(function (value) {return value != null;}); } function () { return this.inject([], function (array, value) {return array.concat(Object.isArray(value) ? value.flatten() : [value]);}); } function () { var values = $A(arguments); return this.select(function (value) {return !values.include(value);}); } function (sorted) { return this.inject([], function (array, value, index) {if (0 == index || (sorted ? array.last() != value : !array.include(value))) {array.push(value);}return array;}); } function (array) { return this.uniq().findAll(function (item) {return array.detect(function (value) {return item === value;});}); } function () { return [].concat(this); } function () { var results = []; this.each(function (object) {var value = Object.toJSON(object);if (!Object.isUndefined(value)) {results.push(value);}}); return "[" + results.join(", ") + "]"; } As you can see, it shows the 6 elements in the array that I want, but it also shows random elements. By the way, I can fix this by changing it to a normal for loop, but I want to know what I'm doing wrong. I have a mortgage calc that is adding an extra decimal place to my interest rate. To see this in action go to: http://www.keithknowles.com/elmtree/mortgagecalc2.htm Change the interest rate to 7.5 Click Calculate Payment Click Create Amortization Chart On the following screen you'll see a recap of your data and the interest rate will now say 7.55. Same thing happens if you enter 6.2. Next screen shows 6.22/ I've attached the html and js files in a zip. Any help is greatly appreciated. Thanks. Hi-- I have found a neat trick to refresh an iframe in an html page, but I just need one little twist to make it work just right. I would like to make the iframe content refresh just once, not matter how many times the link is clicked... Right now, I have this in the head: Quote: <script type="text/javascript"> function refreshIframe(el) { var f = document.getElementById(el) var rsrc = f.src f.src="about:blank" f.src=rsrc } </script> And this is the link which, when clicked, refreshes the iframe every time it is clicked: Quote: <a href="#page_7c" onclick="refreshIframe('test'); return false"> "test" is the id of the iframe. I am sure how to do this is really simple, but it escapes me... Many thanks! hi guys i have a form and i am using javascript to make the password. The problem is i want to use multiple users however it doesn't work when i place a comma in so do you have any suggestions? i will put the code below thanks. Code: /*the following code checkes whether the entered userid and password are matching*/ if(form.userid.value == "darran" && form.pswrd.value == "password") I integrate TinyMCE with a web application. After plugging in TinyMCE, a textarea shows up on a place where no textarea is defined. So far, this problem happens on a web page with multiple textareas. It seems to be caused by either <fieldset> tag or a <TEXTAREA .. readonly>. A non-defined textarea shows on the top of these elements. Does anyone else run into the same problem? Thanks. Hello. I'm trying to open extra information if a user clicks on a TD, and close it if he click on it again. How I can do this? All I learned to do is to show it, but I can't find something that hide it if I click on the same place. Thanks for help. __________________ הורדות I have just used an Analysis Quiz tool (on this page http://javascript.about.com/library/blquizf.htm) to create a quiz which doesn't have right or wrong answers but adds the scores of the answers together. It all works nicely, HOWEVER I require 5 answers as opposed to the maximum of four which has been offered on this site. The (partial) code is: Code: var quiz = new Array(); var r = 0; var analPage = 'result.html'; quiz[r++] =('93726~71~1. How often do you have a drink containing alcohol?~Never~Once a month or less~2 to 4 times a month~2 to 3 times a week~0~3'); quiz[r++] =('48844~37~How many units of alcohol do you have on a typical day when you are drinking?~1-2~3-4~5-6~7-9~0~3'); I thought it would be straight forward and I could add another option at the end of each string and then change the scoring e.g. quiz[r++] =('93726~71~1. How often do you have a drink containing alcohol?~Never~Once a month or less~2 to 4 times a month~2 to 3 times a week~4 or more times a week~0~4'); but this didn't work ... please help! Thank you |