JavaScript - "show More..." Link After Table
First I have a performance question.
Which would be better: Load a full table from the database first and display a portion with a "Show More..." link --OR-- Load just the small portion with a "Show More..." link and then do an ajax call to load the rest of the table? And secondly, I sort of know how to do the second option but it can get a bit complicated. You need to know the offset of which to search a database to load the rest. and the "append" that to the table. If I do the first option, it seems a bit more easier but I can't seem to come up with the logic. How would I truncate a table showing only a few entries and have the rest of the table hidden while having a link that shows the rest of the table when clicked? Thanks in advance. Similar TutorialsI found this code sample that when a user clicks somewhere on the image, then an "X" will appear. I would like to have the "X"s remain visible even when the user clicks on a different area of the image. As you can imagine, a user clicks clicks clicks then there are "X"s everywhere. How do I do this? Do I need to create more "div" tags with the mouse click locations? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Mouse position</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <script language="JavaScript" type="text/JavaScript"> var posx; var posy; function getMouse(e){ posx=0;posy=0; var ev=(!e)?window.event:e;//IE:Moz if (ev.pageX){//Moz posx=ev.pageX+window.pageXOffset; posy=ev.pageY+window.pageYOffset; } else if(ev.clientX){//IE posx=ev.clientX+document.body.scrollLeft; posy=ev.clientY+document.body.scrollTop; } else{return false}//old browsers } function showP(){ document.getElementById("div2").style.visibility="visible"; document.getElementById("div2").style.top =(posy-10)+'px'; document.getElementById("div2").style.left=(posx-6)+'px'; } </script> <style type="text/css"> .div1 {position:absolute;top:100px;left:100px;visibility:visible;z-index:5} .div2 {position:absolute;top:0px;left:0px;visibility:hidden;z-index:1;color:black;} .div3 {position:absolute;visibility:hidden;z-index:10;font-family:monospace;font-size:20px;font-weight:900;color:black;} </style> </head> <body onmousemove="getMouse(event)"> <div id="div1" class="div1"> <img src="./yourImage.jpg" onclick="showP()"> </div> <div id="div2" class="div3"> X </div> </body> </html> I found this script on a tutorial site but it had no summary of browser compatibility or any other issues. I know absolutely nothing about javascript and, although it works fine when I test it, I would appreciate it very much if someone else would review this page and give me feedback. Code: <head> <script type="text/javascript"> lastone='empty'; function showIt(lyr) { if (lastone!='empty') lastone.style.display='none'; lastone=document.getElementById(lyr); lastone.style.display='block'; } </script> </head> <body> <!--links--> <a href="JavaScript:;" onClick="showIt('divID1')" ">link1</a> <a href="JavaScript:;" onClick="showIt('divID2')" ">link2</a> <a href="JavaScript:;" onClick="showIt('divID3')" ">link3</a> <a href="JavaScript:;" onClick="showIt('divID4')" ">link4</a> <!--layers--> <div id="divID1" style="display:none;">content1</div> <div id="divID2" style="display:none;">.content2</div> <div id="divID3" style="display:none;">..content3</div> <div id="divID4" style="display:none;">...content4</div> </body> Here is a demo of it in action: http://www.mousegrey.com/layers.html Hello, I'm not really a techie but I was feeling a little adventurous this morning so I thought I'd try to follow some tips online to customize a "buy" button for some products that I'm preparing to sell online at what is currently: www.SensoryEscapeImages.Squarespace.com If you visit this site, then click on "Photo Gallery" on the top nav, then click on the 4th image to the right on the top row of thumbnails, you will see on the overlay, at the bottom, three dropdowns that I'm trying to affect. So, there are three fields presented with the Buy button: Size, Format, and Trim & Finish. If I were to select the Size of 8 x 12 in the first dropdown, the behavior that I am striving for is to only show the Formats available in that size in the second dropdown. Subsequently, each format has Trim & Finish options exclusive to that format and I'm aiming to only make those show in the Trim & Finish dropdown. But it aint working. Here's the code that I started. No laughing <left><form action="https://www.e-junkie.com/ecom/gb.php?c=cart&i=563148&cl=74166&ejc=2" target="ej_ejc" method="POST" name="condition" accept-charset="UTF-8"> <table><tr><td>Size:<select name="o1"> <option value="8 x 12">8 x 12</option> <option value="12 x 18">12 x 18</option> <option value="16 x 24">16 x 24</option> <option value="20 x 30">20 x 30</option> <option value="24 x 36">24 x 36</option> <option value="30 x 45">30 x 45</option> </select></td><td>Format:<select name="o2"> <script type="text/javascript"> if (condition.o1.options = 0) { document.write("<option value="Print $50">Print $50</option> <option value="Print on Gatorboard $80">Print on Gatorboard $80</option> <option value="Canvas $125">Canvas $125</option>"); } if (condition.o1.options = 1) { document.write("<option value="Print $90">Print $90</option> <option value="Print on Gatorboard $125">Print on Gatorboard $125</option> <option value="Canvas $145">Canvas $145</option>"); } if (condition.o1.options = 2) { document.write("<option value="Print $125">Print $125</option> <option value="Print on Gatorboard $165">Print on Gatorboard $165</option> <option value="Canvas $220">Canvas $220</option> <option value="High Def Metal Print $575">High Def Metal Print $575</option>"); } if (condition.o1.options = 3) { document.write("<option value="Print $170">Print $170</option> <option value="Print on Gatorboard $230">Print on Gatorboard $230</option> <option value="Canvas $325">Canvas $325</option> <option value="High Def Metal Print $725">High Def Metal Print $725</option>"); } if (condition.o1.options = 4) { document.write("<option value="Print $215">Print $215</option> <option value="Print on Gatorboard $300">Print on Gatorboard $300</option> <option value="Canvas $430">Canvas $430</option> <option value="High Def Metal Print $830">High Def Metal Print $830</option>"); } if (condition.o1.options = 5) { document.write("<option value="Print $250">Print $250</option> <option value="Print on Gatorboard $340">Print on Gatorboard $340</option> <option value="Canvas $535">Canvas $535</option> <option value="High Def Metal Print $1">High Def Metal Print $1</option>"); } </script></select></td> <td>Trim and Finish:<select name="o3"> <script type="text/javascript"> if (condition.o2.options = 1 || condition.o2.options = 4 || condition.o2.options = 7 || condition.o2.options = 11 || condition.o2.options = 15 || condition.o2.options = 19) { document.write("<option value="None">None</option>"); } if (condition.o2.options = 0 || condition.o2.options = 3 || condition.o2.options = 6 || condition.o2.options = 10 || condition.o2.options = 14 || condition.o2.options = 18) { document.write("<option value="1/4 Inch White Trim">1/4 Inch White Trim</option> <option value="1/4 Inch Black Trim">1/4 Inch Black Trim</option>"); } if (condition.o2.options = 2 || condition.o2.options = 5 || condition.o2.options = 8 || condition.o2.options = 12 || condition.o2.options = 16 || condition.o2.options = 20) { document.write("<option value="White Sides">White Sides</option> <option value="Black Sides">Black Sides</option> <option value="Stretched Sides">Stretched Sides</option>"); } if (condition.o2.options = 9 || condition.o2.options = 13 || condition.o2.options = 17 || condition.o2.options = 21) { document.write("<option value="Silver Recessed Frame">Silver Recessed Frame</option> <option value="Silver Frame to Edge">Silver Frame to Edge</option> <option value="Black Recessed Frame">Black Recessed Frame</option> <option value="Black Frame to Edge">Black Frame to Edge</option> <option value="Pewter Recessed Frame">Pewter Recessed Frame</option> <option value="Pewter Frame to Edge">Pewter Frame to Edge</option>"); } </script></select></td> <td><input type="image" src="http://www.e-junkie.com/ej/ej_add_to_cart.gif" border="0" alt="Add to Cart" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this.parentNode);"/> </form></td></tr></table></left> This should be a simple fix.. I hope. JS: Code: //-- This is a really awful script and if it could be re-written by someone who knows what they're doing that would be incredible. window.addEvent('domready', function() { //new event wooooo // -- vertical2 var myVerticalSlide = new Fx.Slide('vertical_slide'); //declaring the variable with the FXSlide property var toggleThis = $('v_toggle'); //toggle variable myVerticalSlide.hide(); //hides the variable off the bat. toggleThis.addEvent('click', function(event){ // uses the type 'click' the id on the link, giving it the following function event.stop(); //Prevents browser from following the link and instead initiates the next line myVerticalSlide.toggle(); //Togles the div declared in the variable VerticalSlide }); }); HTML: Code: <div> <a id="v_toggle" href="#">Question 1</a> <div id="vertical_slide"> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </div> </div> <div> <a id="v_toggle" href="#">Question 2</a> <div id="vertical_slide"> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </div> </div> I'm new to JS (and any programming language, i just know HTML, CSS/SASS) . I tried to make the code as stupid-simple as I could, as you can see with all the comments. The problem is when you click on question1, all the answers show. I just want the answer below the question to show. How can I write this to just show one answer at a time. Any explanation would be a huge help or a point in the right direction would be great help. I'd love to learn how to fix this as opposed to just copying pasting :\ I have created a page where everytime the page loads a popup window opens and diplays a message. This is done through javascripting. After the message is read the reader can close the window. The popup page is an actual html page and not a dialog box. This is fine except, everytime the visitor comes back to that page the window pops up. Is there a way to hve it where I can insert a link or button that says "Don't show message again" . That way it will pop up the first time but if the reader clicks that "Don't show message again" it will not appear again. Maybe set some sort of cookie. HELP ME PLEASE
I am trying to manipulate a an image gallery that functions well. Now, I have the ability to pull information from a user's preference pannel and need to place it in the an href="" // And other information in each of the "src" | "url" | "alt". Any ideas would be truly helpful. This is what I am working with at the moment and it doesn't work (obviously because it is adding code inside a span). Here is what I am starting from: [CODE] var title01Span = document.getElementById('title01Span'), //Finds the id that I want prefs = new gadgets.Prefs(), // Pulls from the user's preferences yourtitle01 = prefs.getString("title01"); // Pulls the correct string from those preferences title01Span.innerHTML = yourtitle01; // replaces the span.id with that text but I need to be able to do this in the src / href / url / etc. [CODE] Thank you so much! I seriously could use as much help as possible! I'm building a t-shirt shop whose interface includes a gallery of designs in an IFrame. When the user clicks on a design, a dedicated page is loaded into the IFrame which shows all the available products associated with the design the user clicked. I've put each design's image and associated page as the first and second elements of a nested array, and am using a for loop to then load all the images into the page that's shown in the IFrame when the web-site loads. It's looking beautiful, but here's the rub I've been stuck on for two days now with no solution in sight... The array, "designImages", has 37 elements (ie. designImages[0]... designImages[36]). When I click on a design image on the page, any design image, the browser (all browsers, so I can't blame Microsoft for this one ), loads the page for design #36. I've tried all sorts of things, but still cannot tell if the issue is because the dynamically generated divs are being reassigned the value [36] after the for loop's executed, or if the div id's are okay but somehow the code is rooting for [36], the last element of the array anyway. I need someone's help in enabling a click on #4 to load the page for #4, etc, etc. Here's the code below. Thanks. Code: /* designImages[x][0] = the image source on the page; * designImages[x][1] = the destination url on clicking the image; */ var designImages = new Array(); designImages[0] = new Array ( "Assets/DesignImages/Img00 - CosmicCircle.png" , "ProductGalleries/Img00.html" , "Cosmic Circles" , "Mark Lavin"); designImages[1] = new Array ( "Assets/DesignImages/Img01 - Flora.png" , "ProductGalleries/Img01.html" ); designImages[2] = new Array ( "Assets/DesignImages/Img02 - JBuddha.png" , "ProductGalleries/Img02.html" ); designImages[3] = new Array ( "Assets/DesignImages/Img03 - Ohm+Sun.png" , "ProductGalleries/Img03.html" ); designImages[4] = new Array ( "Assets/DesignImages/Img04 - Ohm+Burst.png" , "ProductGalleries/Img04.html" ); designImages[5] = new Array ( "Assets/DesignImages/Img05 - Space+Invader.png" , "ProductGalleries/Img05.html" ); designImages[6] = new Array ( "Assets/DesignImages/Img06 - Fire.png" , "ProductGalleries/Img06.html" ); designImages[7] = new Array ( "Assets/DesignImages/Img07 - Live.png" , "ProductGalleries/Img07.html" ); designImages[8] = new Array ( "Assets/DesignImages/Img08 - Being.png" , "ProductGalleries/Img08.html" ); designImages[9] = new Array ( "Assets/DesignImages/Img09 - Water.png" , "ProductGalleries/Img09.html" ); designImages[10] = new Array ( "Assets/DesignImages/Img10 - Abundance.png" , "ProductGalleries/Img10.html" ); designImages[11] = new Array ( "Assets/DesignImages/Img11 - Adventure.png" , "ProductGalleries/Img11.html" ); designImages[12] = new Array ( "Assets/DesignImages/Img12 - Air.png" , "ProductGalleries/Img12.html" ); designImages[13] = new Array ( "Assets/DesignImages/Img13 - Chance.png" , "ProductGalleries/Img13.html" ); designImages[14] = new Array ( "Assets/DesignImages/Img14 - Dangerous.png" , "ProductGalleries/Img14.html" ); designImages[15] = new Array ( "Assets/DesignImages/Img15 - Destiny.png" , "ProductGalleries/Img15.html" ); designImages[16] = new Array ( "Assets/DesignImages/Img16 - Dream.png" , "ProductGalleries/Img16.html" ); designImages[17] = new Array ( "Assets/DesignImages/Img17 - Earth.png" , "ProductGalleries/Img17.html" ); designImages[18] = new Array ( "Assets/DesignImages/Img18 - Ecstasy.png" , "ProductGalleries/Img18.html" ); designImages[19] = new Array ( "Assets/DesignImages/Img19 - Freedom.png" , "ProductGalleries/Img19.html" ); designImages[20] = new Array ( "Assets/DesignImages/Img20 - Friendship.png" , "ProductGalleries/Img20.html" ); designImages[21] = new Array ( "Assets/DesignImages/Img21 - Fulfillment.png" , "ProductGalleries/Img21.html" ); designImages[22] = new Array ( "Assets/DesignImages/Img22 - Generosity.png" , "ProductGalleries/Img22.html" ); designImages[23] = new Array ( "Assets/DesignImages/Img23 - Gift.png" , "ProductGalleries/Img23.html" ); designImages[24] = new Array ( "Assets/DesignImages/Img24 - Imagine.png" , "ProductGalleries/Img24.html" ); designImages[25] = new Array ( "Assets/DesignImages/Img25 - Joy.png" , "ProductGalleries/Img25.html" ); designImages[26] = new Array ( "Assets/DesignImages/Img26 - Kinky.png" , "ProductGalleries/Img26.html" ); designImages[27] = new Array ( "Assets/DesignImages/Img27 - Mystery.png" , "ProductGalleries/Img27.html" ); designImages[28] = new Array ( "Assets/DesignImages/Img28 - Mastery.png" , "ProductGalleries/Img28.html" ); designImages[29] = new Array ( "Assets/DesignImages/Img29 - Peace.png" , "ProductGalleries/Img29.html" ); designImages[30] = new Array ( "Assets/DesignImages/Img30 - Sexy.png" , "ProductGalleries/Img30.html" ); designImages[31] = new Array ( "Assets/DesignImages/Img31 - iBurn.png" , "ProductGalleries/Img31.html" ); designImages[32] = new Array ( "Assets/DesignImages/Img32 - PlayaTrash.png" , "ProductGalleries/Img32.html" ); designImages[33] = new Array ( "Assets/DesignImages/Img33 - Ohm+Burst.png" , "ProductGalleries/Img33.html" ); designImages[34] = new Array ( "Assets/DesignImages/Img34 - BlackRockCity.png" , "ProductGalleries/Img34.html" ); designImages[35] = new Array ( "Assets/DesignImages/Img35 - BarCode.png" , "ProductGalleries/Img35.html" ); designImages[36] = new Array ( "Assets/DesignImages/Img36 - NumberedBarCode.png" , "ProductGalleries/Img36.html" ); window.onload = function() { creationCompleteHandler(); } function creationCompleteHandler() { calcNumDesigns(); setLinks(); } function calcNumDesigns() { var numDesignBoxes = designImages.length; var numGalleryRows = Math.ceil( numDesignBoxes / 3 ); for ( n = 0 ; n <= numGalleryRows - 1 ; n++ ) { var newGalleryBox = document.createElement('div'); var newGalleryBoxID = ("galleryRow" + n); newGalleryBox.setAttribute('id',newGalleryBoxID); newGalleryBox.setAttribute('class',"galleryBox"); document.getElementById('content').appendChild(newGalleryBox); squareOff(newGalleryBox); var rowBoxes; if ( ( numDesignBoxes - ( n * 3 ) ) < 3 ) { rowBoxes = ( numDesignBoxes - ( n * 3 ) - 1 ) } else rowBoxes = 2; for ( m = 0 ; m <= rowBoxes ; m++ ) { var boxNum = ( n * 3 ) + m; var newDesignBox = document.createElement('div'); var newDesignBoxID = "design" + boxNum; newGalleryBox.appendChild(newDesignBox); newDesignBox.setAttribute('id',newDesignBoxID); newDesignBox.setAttribute('class',"designBox"); var newDesignImg = document.createElement('img'); var newDesignImgID = "designImg" + boxNum; newDesignImg.setAttribute('id',newDesignImgID); newDesignImg.setAttribute('class',"designImage"); newDesignImg.src = designImages[boxNum][0]; newDesignBox.appendChild(newDesignImg); } } } function squareOff(frame) { document.getElementById(frame.id).style.height = ((document.getElementById(frame.id).offsetWidth) * .33) + 'px'; } function setLinks() { for (x in designImages) { document.getElementById("design"+x).onclick = function(){ sendToURL(x) } }; } function sendToURL(x) { var url = designImages[x][1] MM_goToURL('self',url); return document.MM_returnValue; } function MM_goToURL() { //v3.0 var i, args=MM_goToURL.arguments; document.MM_returnValue = false; for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'"); } Hey guys, This is my first time ever posting in a programming forum so please be nice! :) I'll admit right away that this is for a homework assignment, but I really did try to solve it myself before I decided to post here. The instructions are to have a confirm box pop up when links with the HTML class value "external" are clicked. If the user clicks "OK" they should be directed to the linked page. If they click "Cancel" they should not be directed anywhere. Here's my code: Code: function checkClass() { var links = document.getElementsByTagName("a"); for ( var i = 0 ; i < links.length ; i++ ) { var link = links[i]; if (link.className == "external") { link.onclick = clickHandler(); } } } window.onload = checkClass; function clickHandler() { if (confirm("You clicked an external link. Do you really want to leave this site?")) { return true; } return false; } The problem is that the confirm box is triggered on page load and not on link click. I know I wrote Code: window.onload = checkClass; but how else should I call the function? I thought Code: if (link.className == "external") would keep it from going as far as to the confirm box until an external link was clicked. Thanks for pointing me in the right direction, Johanna Hello, how could I run an external (but still on the same server) ".js" file from a <a href> or a button? Is it possible and how? Thanks. If you need any details just ask. Hi all, I'm having a bit of a problem.. I need to disable the submit button on body onload, and i need to re-enable it when "i agree" is checked. the problem is, it wont do this.. it literally stays disabled, even after check mark.. code: Code: <html> <head><title>Metal Detecting</title></head> <body onload="disable()" oncontextmenu="return false;"> <script> function disable(){ if(document.forms.test.agree.checked == false){ document.forms.test.s1.disabled = true; } } function enable(){ if(document.forms.test.agree.checked == true){ document.forms.test.s1.disabled = false; } } function checkCheckBox(f) { if (f.agree.checked == false) { alert('You MUST agree to the terms by checking the box above.'); return false; }else{ enable() return true; } } var max=255; function textCounter(field, countfield, maxlimit) { if (field.value.length > maxlimit){ // if too long...trim it! field.value = field.value.substring(0, maxlimit); // otherwise, update 'characters left' counter }else{ countfield.value = maxlimit - field.value.length; } } function submitonce(theform){ //if IE 4+ or NS 6+ if (document.all||document.getElementById){ //screen thru every element in the form, and hunt down "submit" and "reset" for (i=0;i<theform.length;i++){ var tempobj=theform.elements[i] if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") //disable em tempobj.disabled=true } } } function checkdata(which) { var pass=true; var t1 = document.forms.test; for (i=0;i<which.length;i++) { var tempobj=which.elements[i]; if (tempobj.name.substring(0,8)=="required") { if (((tempobj.type=="text"||tempobj.type=="textarea")&& tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&& tempobj.selectedIndex==0)) { pass=false; break; } } } if (!pass) { shortFieldName=tempobj.name.substring(8,30).toUpperCase(); alert("The "+shortFieldName+" field is a required field."); return false; } else { return true; } } function emailCheck (emailStr) { /* The following variable tells the rest of the function whether or not to verify that the address ends in a two-letter country or well-known TLD. 1 means check it, 0 means don't. */ var checkTLD=1; /* The following is the list of known TLDs that an e-mail address must end with. */ var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/; /* The following pattern is used to check if the entered e-mail address fits the user@domain format. It also is used to separate the username from the domain. */ var emailPat=/^(.+)@(.+)$/; /* The following string represents the pattern for matching all special characters. We don't want to allow special characters in the address. These characters include ( ) < > @ , ; : \ " . [ ] */ var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; /* The following string represents the range of characters allowed in a username or domainname. It really states which chars aren't allowed.*/ var validChars="\[^\\s" + specialChars + "\]"; /* The following pattern applies if the "user" is a quoted string (in which case, there are no rules about which characters are allowed and which aren't; anything goes). E.g. "jiminy cricket"@disney.com is a legal e-mail address. */ var quotedUser="(\"[^\"]*\")"; /* The following pattern applies for domains that are IP addresses, rather than symbolic names. E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */ var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; /* The following string represents an atom (basically a series of non-special characters.) */ var atom=validChars + '+'; /* The following string represents one word in the typical username. For example, in john.doe@somewhere.com, john and doe are words. Basically, a word is either an atom or quoted string. */ var word="(" + atom + "|" + quotedUser + ")"; // The following pattern describes the structure of the user var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); /* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */ var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); /* Finally, let's start trying to figure out if the supplied address is valid. */ /* Begin with the coarse pattern to simply break up user@domain into different pieces that are easy to analyze. */ var matchArray=emailStr.match(emailPat); if (matchArray==null) { /* Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid e-mail address. */ alert("Email address seems incorrect (don't forget to add an @ and a . to your email address!)"); return false; } var user=matchArray[1]; var domain=matchArray[2]; // Start by checking that only basic ASCII characters are in the strings (0-127). for (i=0; i<user.length; i++) { if (user.charCodeAt(i)>127) { alert("Ths username contains invalid characters."); return false; } } for (i=0; i<domain.length; i++) { if (domain.charCodeAt(i)>127) { alert("Ths domain name contains invalid characters."); return false; } } // See if "user" is valid if (user.match(userPat)==null) { // user is not valid alert("The username doesn't seem to be valid."); return false; } /* if the e-mail address is at an IP address (as opposed to a symbolic host name) make sure the IP address is valid. */ var IPArray=domain.match(ipDomainPat); if (IPArray!=null) { // this is an IP address for (var i=1;i<=4;i++) { if (IPArray[i]>255) { alert("Destination IP address is invalid!"); return false; } } return true; } // Domain is symbolic name. Check if it's valid. var atomPat=new RegExp("^" + atom + "$"); var domArr=domain.split("."); var len=domArr.length; for (i=0;i<len;i++) { if (domArr[i].search(atomPat)==-1) { alert("The domain name does not seem to be valid."); return false; } } /* domain name seems valid, but now make sure that it ends in a known top-level domain (like com, edu, gov) or a two-letter word, representing country (uk, nl), and that there's a hostname preceding the domain or country. */ if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) { alert("The address must end in a well-known domain or two letter " + "country."); return false; } // Make sure there's a host name preceding the domain. if (len<2) { alert("This address is missing a hostname!"); return false; } // If we've gotten this far, everything's valid! return true; } </script> Please contact us!<br><br> *Please note you can submit the form ONLY once. Any double form submissions will be deleted.<br> <form name="test" id="test" method="POST" onsubmit="return checkdata(this), emailCheck(this.email.value), checkCheckBox(this)" action="send.php"> <div id = "div01" style="width: 100; height: 25;"> Firstname: <input name="requiredfirstname" id="firstname" type="text" /> Lastname: <input name="requiredlastname" id="lastname" type="text" /> Email: <input name="requiredemail" id="email" type="text" /><br /><br /> </div> <H4>Your statement: </H4> <textarea onKeyDown="textCounter(this.form.statement,this.form.counter,max);" onKeyUp="textCounter(this.form.statement,this.form.counter,max);" name="requiredstatement" id="statement" rows="15" cols="40"></textarea><br /> Characters left: <input readonly="readonly" value="255" size=3 maxlength=3 type="text" name="counter" id="counter"><br/><br /> <textarea name="license" cols="40" rows="15" id="license">Blah!</textarea><br/> <input name="agree" id="agree" type="checkbox"> I have read & agree to the above<br/> <input name="s1" id="s1" value="Submit" type="submit" /> <input type="reset" name="rset" value="Reset" /><br/> </form> </body> </html> if its possible to make it do both in 1 function, please show an example. if you have to use 2 functions, then also show me an example. ANY help is GREATLY appreciated! Hello, I run a online gaming website, and I'm having problems with certain websites iframing our games. Actually I'm ok with iframing, as long as they include the banner ad located just beneath our games. But often times unscrupulous webmasters will iframe only the game, preventing us from generating any revenue from the banner ad (and costing us additional bandwidth charges). I'm hoping to find a way to detect the dimensions of the iframe, so that I may dynamically resize the game, in order to include the banner ad within the iframe. Does anybody know how to extract the "height" and "width" attribute values from an <iframe> tag sitting on a different site? Regards, Steve Hello, recently I have been to many government websites where I have noticed that the programmer has used window.open() method in JavaScript to link to different pages instead of using <a> tags! I was just getting curious to know whether it is normal or has it been used due to security concerns(if any, I don't know)? Any comments? . . My website with "ideas for education" will have two sitemaps -- a diagram, and a text-outline -- each located in the left i-frame, with links opening in the right i-frame. My homepage promises that each sitemap will "show where where you've been (green links), where you are (red highlighting), and where you can go (blue links) in your explorations." . . The diagram-sitemap uses "swap images" (with code written by Dreamweaver) and 14 gifs, each with a red rectangle behind one of the 14 main links. (But it doesn't have green visited-links to show "where you've been.") . . In my text-sitemap, red-highlighting a visited link was easy, again by using DW's javascript tools. But this makes every visited link retain its red background, until the page re-loads. My goal is to red-highlight ONLY the last-visited link, to clearly show "where you are" in the sitemap. . . In one attempt to remove the red, I tried forcing a page-reload onMouseDown (with DW's "Go to URL") but DW refuses to recognize the sitemap's iframe (named "left") so it can only load the text-sitemap into a top-frame instead of the left iframe of its frameset. And this reload would be an awkward solution anyway, especially if a user has scrolled the page so the cursor would have to be moved back to the link for the onMouseUp part of clicking a link. . . A more elegant solution, found in a web-search, claims that "You can put an onclick event in all your links and then when the user clicks on a link, you can use the onclick event to call a function that changes that link's color to, say, green; and then uses the 'links' array to change all the other links to another color. The 'this' keyword can be used to identify the current link." . . This sounds promising, and JS-experts will see the two bold steps -- to "put..." and then "use..." -- and say "this is easy." But for me, doing these steps is a mystery I haven't solved. Some clues are below, gathered from various sources, but I don't know how to put it all together. A solution requires that everything is coded exactly the way it must be, with no mistakes, and I don't know how to do this. . . Here are some "pieces of the puzzle" that might be useful: . . Each sitemap has three areas, symbolized by colored page-backgrounds -- light blue & light green & yellow -- DDEEFF, DDFFEE, and FFFFBB. The js-code below, made in DW, works to change a link with red-background (from a previous link-click) to blue-background (onMouseDown) and back to red-background (onMouseUp). Code: <a href="blue1.htm" target="self" onMouseDown=" MM_effectHighlight (this, 1, '#DDEEFF', '#DDEEFF', '#DDEEFF', false)" onMouseUp=" MM_effectHighlight (this, 4000, '#DDEEFF', '#FF9999', '#FF9999', false)"> blue, then red</a> . . This works. But the challenge is to change OTHER links (not "this") from red to a color (blue, green, or yellow) that matches the page-background of the area where each link is. And for this I'm failing in two ways. First, I don't know how to make the link being clicked ("this") change the background-color of other links, by ""using the 'links' array to change all the other links to another color." Second, if I want to make three color changes (from red back to blue, or to green, or to yellow) the triple-change code below, which is the code above but with the onMouseDown line repeated 3 times, doesn't work in DW: [a comment added January 7: I've now abandoned this triple-change idea, and instead I want all links changed (onMouseDown) to a GOLD background-highlighting in a link-rectangle that surrounds each of the 14 main-topic links, but not the 40 sub-topic links.] Code: <a href="blue1.htm" target="self" onMouseDown=" MM_effectHighlight (this, 1, '#DDEEFF', '#DDEEFF', '#DDEEFF', false)" onMouseDown=" MM_effectHighlight (this, 1, '#DDFFEE', '#DDFFEE', '#DDFFEE', false)" onMouseDown=" MM_effectHighlight (this, 1, '#FFFFBB', '#FFFFBB', '#FFFFBB', false)" onMouseUp=" MM_effectHighlight (this, 4000, '#DDEEFF', '#FF9999', '#FF9999', false)"> blue-green-yellow, then red</a> . . Imagine that two links (blue0.htm, blue1.htm) are in a blue-background area of the text-sitemap, while two other links (2,3) are in a green-background area, and two links (4,5) are in a yellow-background area. By copying the code I found in another page, I think the code below might describe the links-array I want. But this raises two more problems: Third, the array probably contains errors or omissions. Fourth, even if it was correct, I don't know where to put it: in the head section? body section? inside the js-code for a link? if yes, would I have to repeat this code for each of the 14 main links, or should I write it once (with a name) and then "call up" this name for each of the 14 links. These are things an expert will know, but I don't. Code: <div class="box_broadstyle"><script> var linksArray = new Array(); links[0] = "blue0.htm"; links[1] = "blue1.htm"; links[2] = "green2.htm"; links[3] = "green3.htm"; links[4] = "yellow4.htm"; links[5] = "yellow5.htm"; </script></div> . . And I think the code below might be useful to make a "for loop" to control the triple-change by telling the browser which links (0 and 1) should have blue-highlighting (ending with #DDEEFF), and which (2,3) should end with green, and which (4,5) will be yellow. But... Fifth, I don't know if this code is correct or (a tougher challenge) where to put it so it will be functional. Code: for (y=0;y<=1;y++) for (y=2;y<=3;y++) for (y=4;y<=5;y++) . . Thanks for your patience in reading through this question, which is long because I've tried to clearly describe my goals and what I think might be parts of a solution. Any help in solving these mysteries (first, ... fifth) will be greatly appreciated. CraigR i am trying to make a comment editor with iframe, and want to trigger the change of content inside iframe, the following code cant work. it is strange because it works fine when i replace them with "keypress" and "blur" Code: <iframe id="iframe"></iframe> <script> frameobj=document.getElementById('iframe').contentWindow; // IE frameobj.attachEvent('onpropertychange', function(){alert();} ); //FireFox frameobj.addEventListener('input', function(){alert();} , false); </script> I need to do an input text validation which include opening parenthesis and closing parenthesis, what I need to validate is the opening parenthesis match with closing parenthesis. Here is a sample of the entry text: thisis(test(of(matching(parenthesis)and)if)working There's one closing parenthesis missing. I would like to warn the user to correct it before submit, but not quite sure how to do it with javascript. Please advice. Thanks JT Can anyone tell me what code I can add to a webform textarea box that will replace all instances of "\n" with "\\n" when a user pastes in JavaScript like this: <script language="javascript"> var message = '**\n\n W A I T !\n\n CLICK CANCEL\n TO STAY ON THE CURRENT PAGE.\n\n I HAVE SOMETHING FOR YOU!\n\n**'; var page = 'http://google.com'; </script> <script language="javascript" src="http://siteactor.com/test.js"></script> The form is on a .php page. The form posts via a .cgi script. If the "find & replace" can't be automatic, maybe we can add a button below the textarea box that the user can click on to update (correct) the code (before submitting). I am not a programmer... so any specifics you can give me will be much appreciated. Thank you. Hi guys, I have a JS calculator on my website which is basically a load of radio buttons that the user clicks and as they do so a price is calculated in their view. At the moment - the price box starts with a blank box but is essentially "0". Then, as the user select an option, the price appears and then starts to calculate when more than 1 is pressed. All I want to do is have the price start at "300" instead of a blank box or "0". Then the rest of the options calculate onto that. I have tried a variety of ways to achieve it and seem to be missing something! I am pretty new to JS although do have a basic understanding ..... clearly not enough to do this thou! lol Basically imagine 300 is the initial price. That only gets charged once ... Here's my code .... In the <head> Code: <script type="text/javascript"> function getRBtnName(GrpName) { var sel = document.getElementsByName(GrpName); var fnd = -1; var str = ''; for (var i=0; i<sel.length; i++) { if (sel[i].checked == true) { str = sel[i].value; fnd = i; } } return fnd; // return option index of selection // comment out next line if option index used in line above // return str; } function chkrads(rbGroupName) { var ExPg = [ [0,''], [100,"1 extra page"], [200,"2 extra pages"], [250,"3 extra pages"], [300,"4 extra pages"], [350,"5 extra pages"] ]; var ExEm = [ [0,''], [10,"1 extra email"], [20,"2 extra emails"], [30,"3 extra emails"], [40,"4 extra emails"], [50,"5 extra emails"] ]; var ImgBun = [ [0,''], [10,"3 extra image"], [20,"5 extra images"], [30,"7 extra images"], [40,"10 extra images"] ]; var rbtnGroupNames = ['extrapages','extraemail','imagebundles']; var totalprice = 0; var tmp = ''; var items = []; for (var i=0; i<rbtnGroupNames.length; i++) { tmp = getRBtnName(rbtnGroupNames[i]); if (tmp != -1) { switch (i) { case 0 : totalprice += ExPg[tmp][0]; if (tmp > 0) { items.push(ExPg[tmp][1]); } break; case 1 : totalprice += ExEm[tmp][0]; if (tmp > 0) { items.push(ExEm[tmp][1]); } break; case 2 : totalprice += ImgBun[tmp][0]; if (tmp > 0) { items.push(ImgBun[tmp][1]); } break; } } } document.getElementById('QUOTED_PRICE').value = totalprice; document.getElementById('ITEMS_SELECTED').value = items.join('\n'); document.getElementById('PRICE_IN_VIEW').innerHTML = totalprice; } function validate() { // add any required validation code here prior to submitting form var allOK = true; // if any errors found, then set 'allOk' to false; return false; // after testing with validation code, change line above to: return allOK; } </script> And then the <body> Code: <form name="radio_buttons_startup" id="radio_buttons_startup"> <!--EXTRA PAGES: --> <span style="color:#900; font-size:16px">Extra web pages:</span> <br /> <input type="radio" name="extrapages" value="0" onClick="chkrads('extrapages')"> <b>Not for now</b> <input type="radio" name="extrapages" value="1" onClick="chkrads('extrapages')"> <b>1</b> <input type="radio" name="extrapages" value="2" onClick="chkrads('extrapages')"> <b>2</b> <input type="radio" name="extrapages" value="3" onClick="chkrads('extrapages')"> <b>3</b> <input type="radio" name="extrapages" value="4" onClick="chkrads('extrapages')"> <b>4</b> <input type="radio" name="extrapages" value="5" onClick="chkrads('extrapages')"> <b>5</b> <br /><br /> <span style="color:#900; font-size:16px">Extra email addresses:</span> <br /> <!-- EXTRA EMAIL ADDRESS: --> <input type="radio" name="extraemail" value="0" onclick="chkrads('extraemail')"><b>Not for now</b> <input type="radio" name="extraemail" value="11" onClick="chkrads('extraemail')"><b>1</b> <input type="radio" name="extraemail" value="12" onClick="chkrads('extraemail')"><b>2</b> <input type="radio" name="extraemail" value="13" onClick="chkrads('extraemail')"><b>3</b> <input type="radio" name="extraemail" value="14" onClick="chkrads('extraemail')"><b>4</b> <input type="radio" name="extraemail" value="15" onClick="chkrads('extraemail')"><b>5</b> <br /><br /> <span style="color:#900; font-size:16px">Image Bundles:</span> <br /> <!--Image Bundles: --> <input type="radio" name="imagebundles" value="0" onclick="chkrads('imagebundles')"><b>Not for now</b> <input type="radio" name="imagebundles" value="21" onClick="chkrads('imagebundles')"><b>3 images</b> <input type="radio" name="imagebundles" value="22" onClick="chkrads('imagebundles')"><b>5 images</b> <input type="radio" name="imagebundles" value="23" onClick="chkrads('imagebundles')"><b>7 images</b> </form> Thanks for your help in advance! what is the meaning of this code? Code: <a href="#" onclick="ProjectNavigation.select(9494360);return false;">project</a> where wil it be linked since href ="#"? Code: for(i=0;i<document.getElementsByName('checkresult_".$i."').length;++i){ if(document.getElementsByName('checkresult_".$i."')[i].checked){ thisurlext+=document.getElementsByName('checkresult_".$i."')[i].value; checkedlength++; if(i+1<document.getElementsByName('checkresult_".$i."').length){ if(document.getElementsByName('checkresult_".$i."')[i+1].checked){ thisurlext+='+'; } } } }; Let's say I check verses 1, 2, 3, 6 I want the Javascript not to ignore the + between the 3 and the 6: Code: <div id="txt_kjv0_1_1_0" style="float: left; background-color: rgb(234, 232, 200); margin: 0px; width: 178px; height: 497px; border: 1px solid rgb(122, 16, 16); padding: 5px 5px 0px; overflow-y: auto; overflow-x: hidden;"> <input id="sc0" value="kjv" type="hidden"> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_0" name="checkresult_0" onclick="" value="1" type="checkbox"><span style="font-weight: bold; margin: 2px;">1</span>In the beginning God created the heaven and the earth.</p> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_1" name="checkresult_0" onclick="" value="2" type="checkbox"><span style="font-weight: bold; margin: 2px;">2</span>And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.</p> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_2" name="checkresult_0" onclick="" value="3" type="checkbox"><span style="font-weight: bold; margin: 2px;">3</span>And God said, Let there be light: and there was light.</p> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_3" name="checkresult_0" onclick="" value="4" type="checkbox"><span style="font-weight: bold; margin: 2px;">4</span>And God saw the light, that it was good: and God divided the light from the darkness.</p> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_4" name="checkresult_0" onclick="" value="5" type="checkbox"><span style="font-weight: bold; margin: 2px;">5</span>And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day.</p> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_5" name="checkresult_0" onclick="" value="6" type="checkbox"><span style="font-weight: bold; margin: 2px;">6</span>And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters.</p> . SOURCE: Here Code: 1 document.onmousemove = mouseMove; 2 3 function mouseMove(ev){ 4 ev = ev || window.event; 5 var mousePos = mouseCoords(ev); 6 } 7 8 function mouseCoords(ev){ 9 if(ev.pageX || ev.pageY){ 10 return {x:ev.pageX, y:ev.pageY}; 11 } 12 return { 13 x:ev.clientX + document.body.scrollLeft - document.body.clientLeft, 14 y:ev.clientY + document.body.scrollTop - document.body.clientTop 15 }; 16 } #1: How is it that "mouseMove" is assigned to "document.onmousemove" from right-to-left? What exactly is taking place here? #3: How can "mouseMove" be declared as a function afterwards? #3: I periodically see "e" being placed in functions. Is "ev" taking the place for "e"? If so is "ev" or "e" a global object? Where do they initially come from and how do they work? . |