JavaScript - Random Selection, !=-1 Question
Very, VERY new to javascript, hopefully this question isn't too bad..
So I'm looking at an example of randomly changing a picture through a function, I want to understand *why*, not simply know how.. The confusing code for me is: Code: while (that.src.indexOf(myImages[newImgNumber]) != -1) The other code is irrelevant. My question is, why would testing a current image with a new image result in -1 if they are the same? To me, it seems like it should be !=0? I mean, if I tested if a number was the same as another number, I would expect a result of 0 by subtracting. Is it not subtracting index position to find out if they're the same? Does it simply just return -1 if they are the same, and I'm over thinking it? Thanks for any help. Similar TutorialsOk, I am working on a webpage and on one page section I have 3 random facts. Now, having to change the three random facts to three different random facts every week will be a annoyance. So I need help in creating a code that will allow 3 random facts to chosen every Sunday(for example). Is it possible to do this? Also I can not do this in php. Hello, We are conducting a ceremony in an Auditorium where 336 People are gathered and afterwards we want to choose 20 of them randomly. We want to display the whole act of choosing them via projectors on the auditorium screen with a little animation. Basically the concept of the animation goes like this: http://summercampdubai.com , but we are stuck on the code as none of us knows programming that much: we want the chairs to be GRAY and the one that miss the opportunity (randomly) to turn RED (this much we have done) and the last chair (winner) to REMAIN GRAY (this is where we are stuck)r. PS. can anybody help us with this by tomorrow 10:00 AM GMT? Regards, Sara Hi, im trying to make a quiz. Now, what I have realized is that I can make a random number coincide with a question. But then I'd have to do a huge amount of if statements. Is there a MUCH simpler way of doing this? And also the questions CAN NOT repeat. Please try and keep it simple, as I'm trying to learn. There's 10 questions by the way. Thanks in advance! Hey I'm somewhat new to the javascript world because 95% of my website is HTML so, if you will, I need help writing the javascript for a Random Question Generator...basicly all I have is Code: <script type="text/javascript"> var Q = new Array() Q[1] = "What is your favorite color?"; Q[2] = "What is your favorite animal?"; Q[3] = "What is your favorite place?"; </script> In the real one, there will be about 20 questions and I will need it to choose a quetion randomly out of the 20. As I said i am a beginer so as simple as possible would be great. Thank You for your help in advance Question about random link generator http://www.javascriptkit.com/script/cut1.shtml I want to use this script to hold a hundred odd links and show 8 random urls at a time in a list separated by a couple of line breaks. (Instead of just one). Could someone pls alter the code to allow me to do this please ... I also hope to keep the js file off the main html page. (naming the file list.js) Could someone also indicate how I do this. Hopefully these questions are easy if you know how etc. So far i havent been able to do it... Would be good if i could add a line to prevent duplicate randomly drawn links appearing in the list of eight.... thanks very much if you able to indicate it..... hi i want to create one java code that do this : 1-one counter is counting 20 to 0. 2-if counter 0 then choose random string between "click one" , "click two" , "click three" and show it. 3-in other table we have three button that name`s are "one" , "two" ,"three". 4-for continue page user must click true button,if user click false button alert "wrong". thx Hey! I have a problem and i have looked all around for an anwser. I need some type of code or script to make my 3 images glow with opacity going in and out. Basically, I have 3 images on a page and I want one of the images to randomly fade in for a couple secs then fade out then repeat somewhere between 4 to 20 secs. But, all the images have the same concept going on with their own random fading in and out (without mouse over). Does anyone know of a script or anything that could do this or if anyone could help me make something like this? Not very good with JS. Thank you for taking the time. Have a good day or night 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> I've looked for a solution to this issue, but it seems like a little different scenario than other situations. I made a system for generating friend requests on Facebook. I have a grid that is 6 x 3, for a total of 18 cells. Each cell has a picture in it, and the picture is linked to the Facebook friend request page. My problem is that since each cell is populated at random from the array, I'm getting lots of repeats. For example, some picutures are in 5 cells, and some are in none. I'm trying to figure out how to make it so that once a picture is used once in the grid, it does not get used again in the same grid. I still want every cell filled at random on each page load, I just want to prevent the repeating. Here's my current code: Code: <script type="text/javascript"> var vip_list=new Array( new Array('http://profile.ak.fbcdn.net/v225/1616/88/s1220771654_2158.jpg','http://www.facebook.com/addfriend.php?id=1220771654'), new Array('http://profile.ak.fbcdn.net/v223/1233/29/s904885342_9055.jpg','http://www.facebook.com/addfriend.php?id=904885342'), new Array('http://profile.ak.fbcdn.net/v229/1574/66/s1752031238_626.jpg','http://www.facebook.com/addfriend.php?id=1752031238'), new Array('http://profile.ak.fbcdn.net/v223/768/71/n661155042_7325.jpg','http://www.facebook.com/addfriend.php?id=661155042'), new Array('http://profile.ak.fbcdn.net/v226/732/26/n1827289885_2478.jpg','http://www.facebook.com/addfriend.php?id=1827289885'), new Array('http://profile.ak.fbcdn.net/v229/1631/70/s1425313768_1140.jpg','http://www.facebook.com/addfriend.php?id=1425313768'), new Array('http://static.ak.fbcdn.net/pics/s_silhouette.jpg','http://www.facebook.com/addfriend.php?id=1667023416'), new Array('http://profile.ak.fbcdn.net/v225/1146/29/s506485704_9532.jpg','http://www.facebook.com/addfriend.php?id=506485704'), new Array('http://profile.ak.fbcdn.net/profile6/270/32/s692160490_8745.jpg','http://www.facebook.com/addfriend.php?id=692160490'), new Array('http://profile.ak.fbcdn.net/v229/114/83/s1218176198_7375.jpg','http://www.facebook.com/addfriend.php?id=1218176198'), new Array('http://profile.ak.fbcdn.net/v226/946/4/s1470171885_4973.jpg','http://www.facebook.com/addfriend.php?id=1470171885'), new Array('http://static.ak.fbcdn.net/pics/s_silhouette.jpg','http://www.facebook.com/addfriend.php?id=1329505888'), new Array('http://static.ak.fbcdn.net/pics/s_silhouette.jpg','http://www.facebook.com/addfriend.php?id=1325496968'), new Array('http://profile.ak.fbcdn.net/v223/1546/92/s1536913202_2017.jpg','http://www.facebook.com/addfriend.php?id=1536913202'), new Array('http://static.ak.fbcdn.net/pics/s_silhouette.jpg','http://www.facebook.com/addfriend.php?id=1624715433'), new Array('http://profile.ak.fbcdn.net/v228/1282/58/s713998257_3682.jpg','http://www.facebook.com/addfriend.php?id=713998257') ); var chosen_vip=Math.floor(vip_list.length*Math.random()); var chosen_vip1=Math.floor(vip_list.length*Math.random()); var chosen_vip2=Math.floor(vip_list.length*Math.random()); var chosen_vip3=Math.floor(vip_list.length*Math.random()); var chosen_vip4=Math.floor(vip_list.length*Math.random()); var chosen_vip5=Math.floor(vip_list.length*Math.random()); var chosen_vip6=Math.floor(vip_list.length*Math.random()); var chosen_vip7=Math.floor(vip_list.length*Math.random()); var chosen_vip8=Math.floor(vip_list.length*Math.random()); var chosen_vip9=Math.floor(vip_list.length*Math.random()); var chosen_vip10=Math.floor(vip_list.length*Math.random()); var chosen_vip11=Math.floor(vip_list.length*Math.random()); var chosen_vip12=Math.floor(vip_list.length*Math.random()); var chosen_vip13=Math.floor(vip_list.length*Math.random()); var chosen_vip14=Math.floor(vip_list.length*Math.random()); var chosen_vip15=Math.floor(vip_list.length*Math.random()); var chosen_vip16=Math.floor(vip_list.length*Math.random()); var chosen_vip17=Math.floor(vip_list.length*Math.random()); document.write('<center>'); document.write('<a href="',vip_list[chosen_vip][1],'" target="_blank"><img src="',vip_list[chosen_vip][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip1][1],'" target="_blank"><img src="',vip_list[chosen_vip1][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip2][1],'" target="_blank"><img src="',vip_list[chosen_vip2][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip3][1],'" target="_blank"><img src="',vip_list[chosen_vip3][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip4][1],'" target="_blank"><img src="',vip_list[chosen_vip4][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip5][1],'" target="_blank"><img src="',vip_list[chosen_vip5][0],'" height="60" width="60"></a>'); document.write('<br>'); document.write('<a href="',vip_list[chosen_vip6][1],'" target="_blank"><img src="',vip_list[chosen_vip6][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip7][1],'" target="_blank"><img src="',vip_list[chosen_vip7][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip8][1],'" target="_blank"><img src="',vip_list[chosen_vip8][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip9][1],'" target="_blank"><img src="',vip_list[chosen_vip9][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip10][1],'" target="_blank"><img src="',vip_list[chosen_vip10][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip11][1],'" target="_blank"><img src="',vip_list[chosen_vip11][0],'" height="60" width="60"></a>'); document.write('<br>'); document.write('<a href="',vip_list[chosen_vip12][1],'" target="_blank"><img src="',vip_list[chosen_vip12][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip13][1],'" target="_blank"><img src="',vip_list[chosen_vip13][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip14][1],'" target="_blank"><img src="',vip_list[chosen_vip14][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip15][1],'" target="_blank"><img src="',vip_list[chosen_vip15][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip16][1],'" target="_blank"><img src="',vip_list[chosen_vip16][0],'" height="60" width="60"></a>'); document.write('<a href="',vip_list[chosen_vip17][1],'" target="_blank"><img src="',vip_list[chosen_vip17][0],'" height="60" width="60"></a>'); document.write('<br>'); </script> Any suggestions? Thank you! ok i have to selection boxes and they need to read each other and input either a yes or a no into a text form i would really appreciate some help thanks heres what i have if it helps Code: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" /> <title>Galvanic Corrosion Chart</title> </head> <body> <br /> <form name="gcc"> <div align="center"><a href="website.html"><img style="border: 0px solid ; width: 278px; height: 50px;" alt="" src="pics/LOGO.png" border="0" height="50" width="278" /></a><br /> </div> <p style="text-align: center;" align="center"><font size="+2"><span style="font-family: Century Gothic;"><font style="text-decoration: underline;" size="+3"> <font face="Futura Bk BT">Galvanic Corrosion Chart<span style="text-decoration: underline;"><span style="text-decoration: underline;"><span style="text-decoration: underline;"><span style="text-decoration: underline;"><span style="text-decoration: underline;" /></span></span></span></span></font></font></span></font><font face="Futura Bk BT"><br /> </font> </p> <br /> <table style="text-align: left; margin-left: auto; margin-right: auto;" height="119" width="610"> <tbody> <tr> <td style="vertical-align: top; text-align: center;" align="center" valign="middle"><font face="Futura Bk BT"><font size="+1"> <font size="+1"> Material 1</font></font><br /> <select name="mat1"> <option>Zinc Plating</option> <option>Zinc Die Casting</option> <option>Galvanize</option> <option>Tin-Zinc</option> <option>Cadmium-Zinc Solder</option> <option>Aluminum(Clad.1100.3003.5052.6160)</option> <option>Cadmium Plate</option> <option>Aluminum Castings</option> <option>Carbon & Alloy Steel, Cast Iron</option> <option>Aluminum(2024.2017.7075)</option> <option>Lead</option> <option>Lead-Silver Solder</option> <option>Tin-Lead Solder</option> <option>Tin Plating</option> <option>Chromium Plate</option> <option>Stainless 18/2</option> <option>Copper & Alloys</option> <option>Stainless 18/8</option> <option>Silver Solder</option> <option>Monel</option> <option>Nickel Plate</option> <option>Titanium</option> <option>Silver Plate</option> </select> <br /> </font></td> <td colspan="1" rowspan="1" style="vertical-align: top; text-align: center;" valign="middle"><font face="Futura Bk BT"><font size="+1"> Material 2</font><br /> </font> <select name="mat2"> <option>Zinc Plating</option> <option>Zinc Die Casting</option> <option>Galvanize</option> <option>Tin-Zinc</option> <option>Cadmium-Zinc Solder</option> <option>Aluminum(Clad.1100.3003.5052.6160)</option> <option>Cadmium Plate</option> <option>Aluminum Castings</option> <option>Carbon & Alloy Steel, Cast Iron</option> <option>Aluminum(2024.2017.7075)</option> <option>Lead</option> <option>Lead-Silver Solder</option> <option>Tin-Lead Solder</option> <option>Tin Plating</option> <option>Chromium Plate</option> <option>Stainless 18/2</option> <option>Copper & Alloys</option> <option>Stainless 18/8</option> <option>Silver Solder</option> <option>Monel</option> <option>Nickel Plate</option> <option>Titanium</option> <option>Silver Plate</option> </select> </td> </tr> <tr> <td colspan="2" rowspan="1" align="center" valign="top"><font face="Futura Bk BT" size="+1">Acceptable</font><br /> <font face="Futura Bk BT"><input name="AR" readonly="readonly" /></font></td> </tr> </tbody> </table> </form> </body> </html> Hello all, I usually try and solve my problems by reading all post but i i'm having problem trying to find a solution my problem. I have a simple form in html which presents to the user 2 checkbox's named cash or cheque depending on which answer he gives will present to him 2 different textbox. My problem is i only want the user to be able to select one of the two checkboxes and also i would like the resulting checkbox selected to be placed on the same row. Hope this makes sense!!! I'm only a beginner in javascript and i've found some of the following code on the net but i don't know how to ammend it so that it does what i need it to do. Here is the code: Code: <HTML> <HEAD> <TITLE>Document Title</TITLE> <script> <!-- function c(){} function getresultPay(){ if(document["schDetails"]["chkCash"].checked){ document.getElementById("shwCash").style.visibility="visible" } else{ document.getElementById("shwCash").style.visibility="hidden" } } function d(){} function getresultChex(){ if(document["schDetails"]["chkcheque"].checked){ document.getElementById("shwcheque").style.visibility="visible" } else{ document.getElementById("shwcheque").style.visibility="hidden" } } //--> </script> </HEAD> <BODY> <FORM NAME="schDetails"> <table border="1" width="457"> <tr> <td width="447" align="left" colspan="5" height="12"></td> </tr> <tr> <td width="187" align="left" height="22">Amount to Pay</td> <td width="26" align="center" height="22">:</td> <td width="221" height="22" colspan="3"> <input type = text name ="txtPurCode" tabindex= 25 size="20"></td> </tr> <tr> <td width="187" align="left" height="20">How would you like to pay</td> <td width="26" height="20" align="center"><input type="checkbox" name="chkCash" value="ON" onclick = "c() ; getresultPay()"></td></td> <td width="66" height="20" align="center">Cash</td> <td width="35" height="20" align="center"><input type="checkbox" name="chkcheque" value="ON" onclick = "d() ; getresultChex()"></td></td> <td width="108" height="20" align="center">Cheque</td> </tr> <tr id="shwCash" style="visibility:hidden"> <td width="187">Cash to Pay</td> <td width="26" align="center" height="22">:</td> <td width="221" colspan="3"> <input type = text name ='txtGRTNo' tabindex = 19 size="20"></td> </tr> <tr id="shwcheque" style="visibility:hidden"> <td width="187">Cheque to Pay</td> <td width="26" align="center" height="22">:</td> <td width="221" colspan="3"> <input type = text name ='txtGRTNo' tabindex = 19 size="20"></td> </tr> <tr> <td width="447" align="left" colspan="5" height="12"></td> </tr> </table> </FORM> </BODY> </HTML> I would really appricate if someone could solve this for me. Regards Does anyone know anything about selecting text in an editable iframe? The following code kind of works in FireFox (it's a little buggy), but doesn't work at all in anything else. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>ADVANCED EDITOR TEST PAGE</title> <script type="text/javascript"> function framego(){ document.getElementById("frame").contentDocument.designMode = "On"; document.getElementById("frame").contentWindow.document.body.innerHTML = "TEST [here] ING"; } function selectArea(){ o=document.getElementById('frame'); if(o.contentWindow.getSelection) sel = o.contentWindow.getSelection(); //FF else sel = o.contentDocument.selection.createRange(); //IE range2=sel.getRangeAt(0); var range = document.createRange(); range.setStart(sel.anchorNode,5); range.setEnd(sel.anchorNode,11); //remove the old range and add the newly created range sel.removeRange(range2); sel.addRange(range); o.focus(); } </script> </head> <body onload="framego()"> <iframe id="frame"></iframe> <button onclick="selectArea()">TEST</button> </body> </html> It's supposed to select the word "Here" in the iframe. A million thanks to anyone who can point me in the right direction on this one. :-) Hello, Is there anyway to prevent images, words, divisions, etc from being selected? Also if something is selected is there a way to deselect? Thanks! i have a selection menu here. what i would like to do is that when i select "not copy" it will not show and not copy the contents of "todo" textfield. but when i select any of the "copy text" it will show and copy the contents of the "todo" text. help plsssssssssssssssssss <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form" name="form" method="post" action=""> <p>Phone Number: <input type="text" name="Name" /> </p> <p>Location: <select name="selector" > <option>copy text</option> <option>not copy text</option> <option>copy text</option> <option>copy text</option> </select> </p> <p>To Do Today: <input type="text" name="todo" /> </p> <p> <input type="button" value="Copy" /> </p> </form> </body> </html> I am trying to change text in one cell of a table when a user selects an item from a select menu. The data for the select menu is being pulled from a database (which works fine). The select menu is displayed as expected; however the text in the div tag always comes up as "undefined" The code below is part of a PHP script (thus \" instead of ") I would like to employ a method that does not require extra Javascript in the <head> section as in this instance the code is being output from an include that is called long after the <head> area of the document is processed. Here is what I have Code: <tr><td><select name=\"race\" onchange=\"document.getElementById('ExtraInfo').firstChild.nodeValue = this.options[this.selectedIndex].extrainfo\"> <option selected=\"selected\" value=\"\">Select Race</option>\n"; $sql = mysql_query("SELECT * FROM races");$i=1; while ($row = mysql_fetch_array($sql)){ $output .= "<option value=\"$i\" ExtraInfo=\"{$row['des']}\">{$row['race']}</option>\n"; $i++; } $output .= "</select></td> <td><div id=\"ExtraInfo\">Select Race</div></td></tr> Any help will be greatly appreciated. I found a solution to my problem: by replacing: Code: <select name=\"race\" onchange=\"document.getElementById('ExtraInfo').firstChild.nodeValue = this.options[this.selectedIndex].extrainfo\"> with this: Code: <select name=\"race\" onchange=\"document.getElementById('ExtraInfo').firstChild.nodeValue = this.options[this.selectedIndex].getAttribute('extrainfo')\"> I have 2 textareas, 1 which will be vissible, another that will be hidden. I have a function that mirrors (not in reversed lettering) the first textarea's input to the second. Code: function copy_data(val){ var messageText = document.getElementById(val.id).value document.getElementById('message').innerHTML = messageText; } So that copies from : <textarea name="text_message" rows="4" id="text_message" style="direction:ltr;" onkeyup="copy_data(this)"></textarea><br/> To: <textarea name="message" rows="4" id="message" style="direction:ltr;"></textarea> Then I have another function which when I select text in the "text_message" textarea will apply a tag to it, however I don't want this tag to be vissible in the "text_message" textarea but rather in the "message" textarea. Code: function formatText(el,tag){ var selectedText = document.selection?document.selection.createRange().text:el.value.substring(el.selectionStart,el.selectionEnd); if(selectedText!=''){ var newText=''+tag+''+selectedText+''+tag+''; el.value=el.value.replace(selectedText,newText) } } This effects from this checkbox: <input type="checkbox" id="bold1" name="bold1" onclick="formatText(message,'#28D')" checked="checked" > Could anyone please help me, I think I may have missed something somewhere, because it works if I point it back to "text_message" Hey guys i have been fighting with this issue for some time so I figured i would join this forum and ask for some help for once. Here is what i am trying to accomplish. I have a drop down menu in place to select a month and a year for our owners to select and check their availability calendar. The issue is that i am tired of every month/year going into the code to change the preselected month/year setup less i hear screaming to high heaven from the owners that "The month isnt the current month" constantly. Here is the code i am currently using. <p align="left"><font face="Verdana"> <!--webbot bot="Validation" b-value-required="TRUE" b-disallow-first-item="TRUE" --> <select size="1" name="arrivemonth" value="%%arrivemonth%%"> <option>Select Month</option> <option value="01" SELECTED>January</option> <option value="02">February</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> <option value="06">June</option> <option value="07">July</option> <option value="08">August</option> <option value="09">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select></font></TD> </TR> <TR> <TD bordercolorlight="#808080" bordercolordark="#808080"> <font face="Verdana"> <!--webbot bot="Validation" b-value-required="TRUE" b-disallow-first-item="TRUE" --><select size="1" name="arriveyear" value="%%arriveyear%%"> <option>Select year</option> <option value="2004">2004</option> <option value="2005">2005</option> <option value="2006">2006</option> <option value="2007">2007</option> <option value="2008">2008</option> <option value="2009">2009</option> <option value="2010" SELECTED>2010</option> <option value="2011">2011</option> </select> All i am trying to accomplish is a code that will check the current month and year then preselect the value in the drop down automatically. This information is then fed to a .CGI script to pull data from our local server for their condo availability. Any ideas anyone? Hi, I am trying to use the radio button to display the information for the users. For example, when I click radio button "1", the form should display 1 text box each for first name, last name and so on. When the user clicks on radio button 2, there should be text boxes displayed for user 1 and user 2 to enter their info(first name, last name and so on). I looked at the forum, but couldn't find something similiar.Please advise. Something like ================================ Number of Users 1 2 3 # if radio button 2 is selected then User 1 First Name Last Name User 2 First Name Last Name ================================ The code is as below: <html> <head> <script type="text/javascript"> function showUser() { for(i=0;i<document.form.users.length;i++) { if (document.form.users[i].checked) val=parseInt(document.form.users[i].value); for(j=0;j<=val;j++) { document.form.write("<table cellSpacing=1 cellPadding=0 width=600 border=0>"); document.form.write("<tr> <td width='20%' align='right'><font color="#660000"><b>First Name: </b></font></td>"); document.form.write("<td><input type='text' name='fname1' size='25' maxlength='25'></td></tr>"); document.form.write("<tr><td width='20%' align='right'><font color="#660000"><b>Last Name: </b></font></td>"); document.form.write("<td><input type='text' name='lname1' size='25'maxlength='25'></td></tr>"); document.form.write("</table>"); } } } </script> </head> <form> Check the number of users to display additional input fields.<br><br> <input type="radio" name="users" value="1" onclick = "showUser()"/> 1<br/> <input type="radio" name="users" value="2" onclick = "showUser()"/>2 <br/> <input type="radio" name="users" value="3" onclick = "showUser()"/>3 <br/> </form> </html> ======================================================== Thanks in advance. Hello, I want to create a page that allows the user to select 2 images as options, when they click one, a new page is dynamically loaded with a list of options they can choose again (like a sublevel of the image they clicked on). From there it will just continue moving down like a hierachy Can someone help me with the basic script forthis to work so i can mess with it and edit it to my needs ^ Thank you in advance Basically what I have here in the following code is 15 random numbers that I am supposed to use the bubble and selection sort algorithm to sort. How can I go about getting the numbers to be sorted using selection sort I have already done the bubble. Thanks Code: <html> <body> <script language ="javaScript"> var array = new Array(15); function genNumbers(listbox){ var i; for(i= 0; i < array.length; i++) { array[i] = Math.random()*15; array[i] = Math.round(array[i]); } updateList(listbox); } function sortNumbers(listbox) { var x, y, holder; for(x=0; x < array.length; x++) { for(y=0; y< (array.length-1); y++){ if(array[y] > array[y+1]){ holder = array[y+1]; array[y+1] = array[y]; array[y] = holder; } } } updateList(listbox); } function updateList(listbox) { var i; for(i = 0; i< array.length; i++){ if(listbox.options[i] == null) { listbox.options[i] = new Option(array[i]); } else{ listbox.options[i].text = array[i]; } } } </script> <form> <center> <select name = "ranlist" size "10" style = "width: 100px"> </select> <br><br><br> <input type = "button" value = "Generate" onClick = "genNumbers(this.form.ranlist);"> <input type = "button" value = "Bubble Sort" onClick = "sortNumbers(this.form.ranlist);"> </form> </body> </html> |