JavaScript - Simple "if / Else" For Removing Javascript From Ie
I hardly know anything about javascript and I'm only messing with it to fix a problem with implementing Facebook comments on my website. I'm trying to load only Disqus comments on IE and only Facebook comments for every other browser. I'm somewhat familiar with conditional statements for html and css but not javascript. I have found solutions for inserting and removing other elements but not javascript.
if IE = load Disqus if not IE = load Facebook comments Thanks in advance. Similar TutorialsHello , here is my code(which is not working on my problem) i want to remove anchor tag(href="a") will u please help.... Code: <html> <head><title>Welcome to DevForum</title></head> <script language="javascript" type="text/javascript"> function Remove() { var anchor = document.getElementsByTagName("a"); var i; for(i=0;i<anchor.length;i++) { var anc=anchor.item(i); var href=anc.attributes.getNamedItem("href"); if (href.value == "a") { anchor.item(i).attributes.getNamedItem("href").value = ""; } } } </script> <body onload="Remove()"> <h1>Welcome</h1> <a href="b">b</a> <a href="a">a</a> </body> </html> Thanks in Advance.... 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! Hi, I am building a navbar using suckerfish. The company that I am using to host the site places onload="page_init()" in the <body> tag automatically. This kills the suckerfish js. Is there a way to remove this onload="page_init()" using a js, or will it just kill that js also? 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> 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! Hey everyone, I'm new here so be gentle I ran into a website called livethesheendream.com when the whole charlie sheen drama was going on. I really liked the way the simple site was designed and would like to create something similar to the layout but totally different topic. My question is, can someone modify the script so that when someone clicks on the image or if they click on the "quote" it will show the next quote BUT in the order I want it to be, for example... it will start with "1" when the open the page, then when you click the picture or "1" it will show "2", then "3" and so on. I will write out all the quotes and have the user just click next, next, next. I hope that makes sense. I copied and posted the source code i got from livethesheendream.com if that helps. PM me if you need to, I will be online most the day. Thank you to anyone who can help me! Code: <!doctype html> <html> <head> <title>Live the Sheen Dream</title> <link href="styles/screen.css" rel="stylesheet" type="text/css" /> <meta name="description" content="A random quote generator from Charlie Sheen's recent rants and words of wisdom." /> <meta name="keywords" content="charlie sheen, sheen, quotes, quote generator, meme, charlie sheen crazy, charlie sheen insane, charlie sheen rant, rant, charlie sheen drugs, f-18, winning, charlie sheen winning" /> <meta name="robots" content="index, follow" /> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-21696467-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> </head> <body> <div id="wrapper"> <center><p><a href="http://www.livethesheendream.com/" onclick="randomQuote(); return false;"><img src="http://www.livethesheendream.com/images/sheen.jpg" alt="sheen" /></a></p></center> <h4><p>( click the head. )</p></h4> <h1><blockquote id="quote">Get the cancer out of the mix.</blockquote></h1> <center> <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http://livethesheendream.com/" layout="button_count" show_faces="false" font="arial"></fb:like> </center> <br /> <center> <a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" >Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> </center> <br /> <center><h3> <a href="mailto:info@livethesheendream.com" target="_blank">contact us</a> </h3></center> <script type="text/javascript"> var quotes = ["Good luck on your travels. You\u2019re going to need it. Badly.","Sorry man, didn\u2019t make the rules.","I embarrassed him in front of his children and the world.","I\u2019ve got magic. I\u2019ve got poetry at my fingertips.","Mistook this rockstar, bro.","The only thing I\u2019m addicted to right now is winning.","I\u2019m not Thomas Jefferson. He was a pussy.","My success rate is 100 percent. Do the math.","I\u2019m so tired of pretending my life isn\u2019t perfect and *****in\u2019.","Imagine what I would have done with my fire-breathing fists.","Here\u2019s your first pee test. The next one goes in your mouth. No, you won\u2019t get high.","The scoreboard doesn\u2019t lie. Never has.","I am battle-tested bayonets bro.","Where there were four, there are now three.","Just sit back and enjoy the show.","I have real fame. They have nothing.","Bring me a challenge. Somebody.","Pure and complete gnarly-isms.","There\u2019s my life. Deal with it. Oh, wait, can\u2019t process it? LOSERS.","A lot of people think Major League\u2019s called Wild Thing. As they should.","Why give an interview when you can leave a warning?","There\u2019s a new sheriff in town. And he has an army of assassins.","We work for the pope.","Gnarly gnarlingtons.","I am special, and I will never be one of you.","There are parts of me that are Dennis Hopper.","I don\u2019t live in the middle anymore. That\u2019s where you get embarrassed in front of the prom queen.","Thought you were messing with one dude? Sorry.","WINNING.","WINNING.","I\u2019m going to hang out with these two smoooooking hotties and fly privately around the world.","It might be lonely up here but I sure like the view.","I\u2019m done. It\u2019s on. Bring it.","I wanted to watch Jaws on the ocean in the dark and be afraid.","This guy\u2019s got more notches on his belt than Black Bart.","This is me not on drugs bro.","The first one\u2019s free. The next one goes in your mouth.","This contaminated little maggot can\u2019t handle my power.","Clearly I have defeated this earthworm with my words.","I closed my eyes and in a nanosecond I cured myself.","Quit hiding dude. It\u2019s embarrassing. Next subject.","It\u2019s funny how sheep rhymes with sleep.","Bull S-H-I-T.","I\u2019ve spent close to the last decade effortlessly and magically converting your tin cans into pure gold.","You\u2019ve been warned dude. Bring it.","Apocalypse Now will teach you how to live inside of a moment between a moment.","I have a disease? Bull****. I cured it with my brain.","If you\u2019re a part of my family, I will love you violently.","I look at the game of baseball and I\u2019m reminded of a quote that I wrote.","They couldn\u2019t extinguish my pilot light. And that was a mistake.","I\u2019m 45, I\u2019ve got five kids, and I\u2019ve been dumped on for too long.","One of my favorite poets is Eminem.","Let\u2019s hook up and just bring fiery death.","Watch me bury you.","I don\u2019t sleep. I wait.","Let\u2019s talk about something exciting. Me.","Everybody has a black belt and carries a gun. I don\u2019t mess with people.","I\u2019m rolling out magic, bro.","Go back to the troll hole where you came from.","I\u2019m just giving them what I guess they want, I just don\u2019t know if they can handle it. Pussies.","I guess I\u2019m just that goddamn *****in\u2019.","We\u2019re Vatican assassins. How complicated can it be?","Most of the time- and this includes naps- I\u2019m an F-18.","I don\u2019t know, winning, anyone? Rhymes with winning? Anyone? Yeah, that would be us.","I have one speed. I have one gear. Go.","I dare you to keep up with me.","I am on a drug. It\u2019s called Charlie Sheen.","I\u2019m an F-18 bro.","The run I was on made Sinatra, Flynn, Jagger and Richards look like droopy-eyed armless children.","Your face will melt off and your children will weep over your exploded body.","You should have read the directions before you showed up at the party.","I\u2019ve got tiger blood, man.","Your face will melt off and your children will weep over your exploded body.","I may forget about them tomorrow, but they\u2019ll live with that memory for the rest of their lives. And that\u2019s a gift.","I was banging seven gram rocks and finishing them. Because that\u2019s how I roll.","I have a different constitution.","I use a blender. I use a vacuum cleaner.","I\u2019m bi-winning. I win here, and I win there.","What\u2019s the cure? Medicine?","You borrow my brain for five seconds and just be like 'Dude, can\u2019t handle it. Unplug this *******.'","Basically they strapped on their diapers.","I exposed people to magic.","Shut up. Stop. Move forward.","Wow. What does that mean.","Resentments are the rocket fuel that lives in the tip of my sabre.","I\u2019m tired of pretending I\u2019m not a total, *****in\u2019 rock star from Mars.","Drug tests don\u2019t lie.","It\u2019s a war. And it\u2019s on.","Sorry my life is so much more *****in\u2019 than yours. I planned it that way.","I take great umbrage with that.","I don\u2019t have burnout in my gear box.","I\u2019m just going to sail across the winds of the universe with my goddesses.","That was the America I was raised in.","If people could just read behind the hieroglyphic.","I don\u2019t think people are ready for the message I\u2019m delivering.","They picked a fight with a warlock.","Faith is for winners. Hope is for losers.","Clearly he didn\u2019t bring gum for everyone.","I\u2019m going to win every moment.","That\u2019s the code. And we all live by it.","Here\u2019s your cold coffee. Buh-bye.","Surprise. That\u2019s what winners do.","I can\u2019t make up a hernia. That\u2019s just lame.","It\u2019s a three-letter word. It rhymes with why.","My conduct is *****in\u2019.","Come on bro, I won best picture at 20.","Your perimeter\u2019s been breached. You got work to do bro.","It was so gnarly I can\u2019t remember.","I\u2019m not recovering like some pussy.","Rock bottom? That\u2019s a fishing term.","I\u2019m a grandiose life, and I\u2019m embracing it.","Can\u2019t is the cancer of happen.","Dying is for fools. Amateurs.","When I\u2019m fighting a war there\u2019s no room for sensitivity.","If you can bring me a souvenir from that moment when your father locked you in the closet, then bring it to me.","She was attacking me with a small fork.","What was she doing with a shrimp fork in her purse?","I'm still alive, which is pretty cool.","Women are not to be hit. They are to be hugged and caressed.","I have a 10,000-year-old brain and the boogers of a seven-year-old.","Get over here and enjoy the ride, bro. We\u2019re starting to win.","I\u2019m not taking it. I had to pay for it.","Vintage balderdash.","I\u2019ve been a veteran of the unspeakable.","I literally woke up and it was Christmas.","It\u2019s been a tsunami. And I\u2019ve been riding it on a mercury surfboard.","We\u2019re on a rocket ship to the moon some nights.","I don\u2019t understand what I did wrong except live a life that everyone is jealous of.","Duh, WINNING.","Park your nonsense.","Don\u2019t live in the middle.","Adonis DNA.","We\u2019re shaking the tree. We\u2019re shaking all the trees.","I am grandiose. Because I live a grandiose life.","Celebrate this movement.","Get a job, anyone?","You can\u2019t process me with a normal brain.","I\u2019ve got tiger blood and Adonis DNA.","You\u2019ve been given magic. You\u2019ve been given gold.","Bi-polar? The Earth is bi-polar.","Damn, I didn\u2019t take care of myself. Again.","I just want to hug him and rub his head.","I\u2019m an exciting client.","What\u2019s not to love?","I\u2019m alive. Bring it.","Look at these sad trolls.","I\u2019m a peaceful man with bad intentions.","Sorry Middle America.","Who wants to deal with all the small talk?","Really dude? Really?","The last time I used? What do you mean? I used my toaster this morning.","Everything. Next question.","Can I have one part of my life that isn\u2019t TMZ\u2019d up the butt?","We need his wisdom and his *****in\u2019-ness.","Work fuels the soul.","Winning. Everyday.","Add some gold.","Change your brain.","People can\u2019t figure me out. They can\u2019t process me. I don\u2019t expect them to.","They can\u2019t hang with me. Their bones would melt like wax.","I\u2019m not \u2018aw shucks\u2019. Because I\u2019m gnarly.","Got to dismiss these clowns.","I\u2019m on a quest to claim absolute victory on every front.","Teamwork. Bang.","The wildfires are spreading. The meek are scattering.","They hate themselves first.","Biggest star in the world.","I\u2019m living inside the truth. And the truth doesn\u2019t change.","He has no salt in his soul.","C\u2019mon. The guy wears corduroys.","I honorably pass that torch to these young geniuses.","Change the channel. I dare you.","I\u2019ve been blessed with a new brain.","It\u2019s about winning. Sorry.","*****in\u2019 focus.","Get back in the game dude.","Get the cancer out of the mix.","Gnarly you are not.","Of course you\u2019re gnarly. You\u2019re talking to me.","Wow. That\u2019s epic.","That just flew out. That was a pretty good one.","It's a turd that opens on a tugboat.","If they want me in it, it's a smash.","No panic. No judgement.","Hope is for suckers and tools.","The people would revolt.","You can tell him one thing. I own him.","Missing a lot of good sports, people. Lots.","My passion was asleep for a long time.","I finally extracted myself from their troll hole.","They tell you to lay down your sword. Really? Wow, dude's unarmed. WHACK.","I think you've got a little more magic than you realize.","You make a choice to win, and you win.","I have to tip my hat to them.","There's a reason I've had mad success doing comedy.","Yeah I'll do a movie with you. You're awesome.","I don't forget anything, you know?","I can't pee in front of you guys.","Flinching's for amateurs.","He has no salt in his soul.","It's about winning. Sorry.","They can't really ruffle this assassin's feathers.","We form a group called the wedge.","Panicking is for amateurs and morons.","I don't believe in panicking.","They could have fleeced the sheep a thousand times, but they chose to skin it once.","It feels like the hot springs of Middle Earth are finally ready to explode outward.","It feels like the worm's turning.","It boils and it fuels you. It boils in a state that would eclipse a microwave.","Ride down the face of a tsunami and tell me you don't feel *****in'.","I\u2019m an F-18 bro."]; function randomQuote(){ var quote = document.getElementById("quote"); var rand = Math.ceil( Math.random() * (quotes.length - 1) ); quote.innerHTML = quotes[rand]; } </script> </div><!-- end wrapper --> </body> </html> Code: window.onload = initForms; function initForms(){ for(var i=0; i<document.forms.length; i++){ document.forms[i].onsubmit = function(){ return validForm(); } } } Hi, this is the first part of a long code and I have three questions wondering if anyone could help me.. 1. What is the benifit of having the above code with "window.onload" and "for loop" and loop through the forms if I only have ONE form in html? 2. What is this line of code "document.forms[i].onsubmit" saying? Does it mean "Execute function() when submit button within form[i] has been pressed?" 3. function() - Does this empty function mean "run every following function below"?? Thank you!! 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? 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> 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. 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 suggestions welcome !!
Hi I am trying to load html stream directly into webbrowser in delphi. The html contains java script. It loads xml and xsl files and display the xml content in the web browser. I got an error, says access denied for the command xmlDoc.load(fname); If I save the html into a file, test.html, and double click it, it is fine, no problem. The code is actually copied from w3schools.com. the html code as followed: <html> <head> <script> function loadXMLDoc(fname){var xmlDoc; if (window.ActiveXObject) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); } else { alert('Your browser cannot handle this script'); } xmlDoc.async=false; xmlDoc.load(fname); return(xmlDoc); } function displayResult() { xml=loadXMLDoc("catalog.xml"); xsl=loadXMLDoc("catalog.xsl"); if (window.ActiveXObject) { ex=xml.transformNode(xsl); document.getElementById("example").innerHTML=ex; } } </script> </head> <body id="example" onLoad="displayResult()"> </body> </html> The delphi code is procedure TForm1.WBLoadHTML(WebBrowser: TWebBrowser; HTMLCode: string) ; var v: OleVariant; HTMLDocument: IHTMLDocument2; begin memo1.Lines.LoadFromFile('d:\test\htmltxtold.html'); HTMLCode := memo1.Text; WebBrowser1.Navigate('about:blank') ; HTMLDocument := WebBrowser.Document as IHTMLDocument2; v := VarArrayCreate([0, 0], varVariant); v[0] := HTMLCode; HTMLDocument.Write(PSafeArray(TVarData(v).VArray)); HTMLDocument.Close; end; Thanks a lot This is my first post. I am reading "Javascript The Good Parts" ~ The Method Invocation Pattern Page 28 and tried this, var myObject= { value:0, increment:function(inc){ this.value+= typeof inc==="number" ? inc:1; } } myObject.increment(2); alert(myObject.value); but alert(myObject.value); is returning a value of "2", when it should return "3". Can someone help? Reply With Quote 12-22-2014, 09:59 AM #2 rnd me View Profile View Forum Posts Visit Homepage Senior Coder Join Date Jun 2007 Location Urbana Posts 4,497 Thanks 11 Thanked 603 Times in 583 Posts 0+2=2, not 3; the code is working correctly. Hi - in editing a website...this javascript html is really getting on my nerves - can somebody please tell me why i keep getting the error message expected ")" when i try this code: (which ive fiddled around with bloody loads to try and resolve!) <SCRIPT LANGUAGE=JAVASCRIPT > var r_text = new Array (); r_text[0] = Text 0; r_text[1] = Text 1; r_text[2] = Text 2; var i = Math.floor(3*Math.random()); { document.write("<marquee style="font-family: 'Georgia'; color: #FFFF00; font-size: 13pt; mso-fareast-font-family: 'Arial'" ><scrollamount="15"><b>" + r_text[i] + "</b></scrollamount></marquee>"); } it seems fine to me and is getting me really frustrated now any help greatly appreciated, do whatever you like to the coding if itll work! thankyou very much, joe. I am pretty novice. I do not know much about the compilers or how these things run. I do however have a good eye for trends and can figure just about anything out by looking at it. With that; I have a game that uses a exe launcher with a built in patcher. I have found the code for the launcher. There are several "jquery" scripts for basic components like scroll wheel. There are also things like "downloader.js", "inputs.js". I am interested in seeing what (and more precisely how many) ip addresses are being retrieved. I fear this patcher is using a hidden bittorrent like download system. The code for "downloader" is pretty basic. It clearly uses some other script, but I am wondering if you can point me in the direction of a utility to monitor running JS so that I can see what is being returned. Code: _Downloader = function() { this.downloadStatusCallback = null; } _Downloader.prototype = { setDownloadStatusCallback: function(callback) { this.downloadStatusCallback = callback; }, addDownload: function(downloadName, metaUrl, outputPath, authorizationURL) // returns bool { return document.SSNLauncher.SSNLauncher_ReturnBool('addDownload', 'string:' + downloadName + '|' + 'string:' + metaUrl + '|' + 'string:' + outputPath + '|' + 'string:' + authorizationURL + '|'); }, removeDownload: function(downloadName) // returns bool { return document.SSNLauncher.SSNLauncher_ReturnBool('removeDownload', 'string:' + downloadName + '|'); }, getDownloadOption: function(downloadName, optionName) // returns string { return document.SSNLauncher.SSNLauncher_ReturnString('getDownloadOption', 'string:' + downloadName + '|' + 'string:' + optionName + '|'); }, setDownloadOptions: function(downloadName, enableBitSources, enableWebSources) // returns bool { return document.SSNLauncher.SSNLauncher_ReturnBool('setDownloadOptions', 'string:' + downloadName + '|' + 'bool:' + enableBitSources + '|' + 'bool:' + enableWebSources + '|'); }, getDownloadActive: function(downloadName) // returns bool { return document.SSNLauncher.SSNLauncher_ReturnBool('getDownloadActive', 'string:' + downloadName + '|'); }, setDownloadActive: function(downloadName, active) // returns bool { return document.SSNLauncher.SSNLauncher_ReturnBool('setDownloadActive', 'string:' + downloadName + '|' + 'bool:' + active + '|'); } } function __Downloader_reportdownloadStatus(downloadName, state, active, totalBytes, bytesLeft, maxIncoming, averageIncoming, currentIncoming, maxOutgoing, averageOutgoing, currentOutgoing, bytesRead, bytesSent, scanBytesLeft) { if (SSN.Downloader.downloadStatusCallback != null) { SSN.Downloader.downloadStatusCallback(downloadName, state, active, totalBytes, bytesLeft, maxIncoming, averageIncoming, currentIncoming, maxOutgoing, averageOutgoing, currentOutgoing, bytesRead, bytesSent, scanBytesLeft); } } I have tried on several occasions to teach myself programing. I can get the commands and syntax fairly easily, and I am pretty good at 'coming up' with ways to get something done. I just don't have experience in this field (I'm in medical school) so I do not know about the tools and utilities programers use and scouring the internet has been less than fruitful. Anybody capable of pointing me in the direction of finding a utility to monitor running js (if that is even possible =/). I use dreamweaver CS5 to explore js code. Hi, Please i am confuse to know the work of this sign (!)...which is exclamation sign in programming. i have this code here which which i remove the exclamation sign (!)..it dont work but when i add it ,then it work. Here is the code <script type="text/javascript"> function getvalue() { var mytextfield=document.getElementById("mytext"); if(mytextfield.value!="") { alert("You Entered:"+mytextfield.value) } else{ alert("would you enter some text") } } </script> <input type="text" id="mytext" size="30"> <input type="button" value="check" onclick="getvalue()"> Please help me to understand the use of this sign !. Thank you. Clement Osei. |