JavaScript - Help With Drop Down Messages?
Hi! I was wondering if anyone could help with the code below. I think there is something wrong with the "thecontents[] part below. Could anyone have a look and possible email me with a finished version...
Code: <table border="0" cellspacing="0" cellpadding="0"> <tr> <td width="100%"><form name="ddmessage"><table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td width="100%"><select name="selectbox" size="1" onChange="changecontent(this)"> <option selected value="What is JavaScript?">What is JavaScript?</option> <option value="Why learn JavaScript?">Why learn JavaScript?</option> <option value="What do you think of the site?">What do you think of the site?</option> <option value="I'd like to feature one of these codes on my site.">I'd like to feature one of these codes on my site.</option> </select><br> </td> </tr> <tr> <td width="100%"><textarea rows="8" name="contentbox" cols="35" wrap="virtual"></textarea><br> <font face="arial" size="-2">This free script provided by <a href="http://javascriptkit.com">JavaScript Kit</a></font> </td> </tr> </table> </form> </td> </tr> </table> <p> <script language="JavaScript"> /* Drop down messages script By JavaScript Kit (http://javascriptkit.com) Over 400+ free scripts here! */ //change contents of message box, where the first one corresponds with the first drop down box, second with second box etc var thecontents=new Array() thecontents[0]='Its what I used to make this :/' thecontents[1]='I wouldn't reccommend it, its rather hard. Though, I hate to blow ones own trumpet, I am learning to do it rather well.' thecontents[2]='I hope you have enjoyed it! Email support@matthewjmorris.co.uk with your comments. Also, if you have any bits to go on this page, email Support aswell with the code, instructions for installing the code and your name! Your name may appear here, along with your code!' thecontents[3]='support@matthewjmorris.co.uk' //don't edit pass this line function changecontent(which){ document.ddmessage.contentbox.value=thecontents[which.selectedIndex] } document.ddmessage.contentbox.value=thecontents[document.ddmessage.selectbox.selectedIndex] </script> Thanks! Similar TutorialsI had posted a previous forum for help and solved a problem. However, than the links lost their formatting in the browser. I kept going as I am doing a lesson out of a textbook and the links are fixed now, but my coded object is not showing up. There should be a calendar in the upper righthand corner. I posted the javascript first and only a section of html after. Code: function calendar() { var calDate = new Date("March 18, 2011"); document.write("<table id='calendar_table'>"); writeCalTitle(calDate); writeDayNames(); writeCalDays(calDate); document.write("</table>"); } function writeCalTitle (calendarDay) { var monthName = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); var thisMonth=calendarDay.getMonth(); var thisYear=calendarDay.getFullYear(); document.write("<tr>"); document.write("<th id='calendar_head' colspan='7'>"); document.write(monthName[thisMonth]+" "+thisYear); document.write("</th>"); document.write("</tr>"); } function writeDayNames() { var dayName = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); document.write("<tr>"); for (var i=0; i < dayName.length; i++){ document.write("<th class='calendar_weekdays'> "+dayName[i]+"</th>"); } document.write("<tr>"); } function daysInMonth(calendarDay) { var thisYear = calendarDay.getFullYear(); var thisMonth = calendayDay.getMonth(); var dayCount = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); if (thisyear % 4 == 0) { if((thisyear % 100 != 0) || (thisyear % 400 == 0)){ dayCount[1] = 29; //this is a leap year } } return dayCount[thisMonth]; } function writeCalDays(calendarDay){ var dayCount = 1; var totalDays = daysInMonth(calendarDay); calendarDay.setDate(1); var weekDay = calendarDay.getDay(); document.write("<tr>"); for (var i = 0; i < weekday; i++) { document.write("<td></td>"); } while (dayCount <= totalDays) { if (weekDay == 0) document.write ("<tr>"); document.write("<td class='calendar_dates'>"+dayCount+"</td>"); if (weekday == 6) document.write ("</tr>"); dayCount++; calendarDay.setDate(dayCount); weekDay = calendarDay.getDay(); } document.write("</tr>"); } Code: <title>The Chamberlain Civic Center</title> <link href="ccc.css" rel="stylesheet" type="text/css" /> <link href="calendar.css" rel="stylesheet" type="text/css" /> <script src="cal.js" type="text/javascript"></script> </head> <body> <div id="head"> <script type="text/javascript"> calendar(); </script> <img src="logo.gif" alt="Chamberlain Civic Center" /> </div> If you want, I can upload the files to my school server so you can view the webpage in a browser. The error console says that there is a missing parenthetical where I have the ! symbol. I don't see that. Also it says that calendarDay is not defined. I need help making new messages appearing at the top of the chatbox, not the bottom. Anyone know how to do that? Also, how can I make it hold only X amount of messages then after X amount of messages it just removes the last one. Thanks This isn't all the code but I figure it has to be something within this code that I have to change. If you want to look at the source code to go http://gifts4points.com and take a look there. Code: //Function for initializating the page. function startChat() { //Start Recieving Messages. getChatText(); } //Gets the browser specific XmlHttpRequest Object function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } else { document.getElementById('p_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object. Consider upgrading your browser.'; } } //Gets the current messages from the server function getChatText() { if (receiveReq.readyState == 4 || receiveReq.readyState == 0) { receiveReq.open("GET", 'getChat.php?chat=1&last=' + lastMessage, true); receiveReq.onreadystatechange = handleReceiveChat; receiveReq.send(null); } } //Add a message to the chat server. function sendChatText() { if(document.getElementById('txt_message').value == '') { alert("You have not entered a message"); return; } if (sendReq.readyState == 4 || sendReq.readyState == 0) { sendReq.open("POST", 'getChat.php?chat=1&last=' + lastMessage, false); sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); sendReq.onreadystatechange = handleSendChat; var param = 'message=' + document.getElementById('txt_message').value; param += '&name=<?php echo $_SESSION['login']; ?>'; param += '&chat=1'; sendReq.send(param); document.getElementById('txt_message').value = ''; } } //When our message has been sent, update our page. function handleSendChat() { //Clear out the existing timer so we don't have //multiple timer instances running. clearInterval(mTimer); getChatText(); } Hi all. I'm trying stuff out for learning. What I would like to do is display the first error message in array ie 'required' if its still wrong when validate again I want message two to display ie 'still required' but I can't work it out. As expected, I always get the last message. Can it be done as I would like or is it done another way? Code: var errmail = []; errmail[0]="Required"; errmail[1]="Still required"; errmail[2]="Oi idiot, enter a VALID email"; /other code here/ email checked and failed for (i=0; i<errmail.length; i++) document.getElementById("emerr").innerHTML = errmail[i] ; /other code/ any positive input very welcome LT ps:-)smile On twitter, when you change your avatar/background a small white box covering an inch of the top of the page appears. How can I do this?
I'm trying to make these two messages change every two seconds. I'm not sure if the setInterval needs to be outside of the function. Also, not sure about HTML action"". It's not working and I'm not sure where my mistakes are. Very frustrating. I know it's easy for some of you, please help! <script type="text/javascript"> var curMessage="message1"; var changeMessage="message2"; function adMessage() { if (curMessage) {document.getElementbyId("message").value = "Place your Thanksgiving orders today!"; changeMessage; setInterval ('adMessage()',2000); } else (changeMessage); {document.getElementbyId("message").value = "All orders must be received by November 20th!"; curMessage; setInterval ('adMessage()',2000); } } </script> </head> <body onload="adMessage();"> <h1>Forestville Foods</h1> <h2>Party Platters</h2> <form name="advertising" action="adMessage"> <input type="text" name="message" size="60" value="Place your Thanksgiving orders today!" /> </form> What can I do to find out what the errors in the error console mean?
Hello all, i am new to this forum.. i am validating a form and displaying results.. but, instead of displaying the result in popup(alert), i need to display it as a text that disappears after a few seconds.. Code: function valtext() { if(document.getElementById("functional").value == "") { document.getElementById("label").innerHTML=message; startTimer(); } } function hideMessage() { document.getElementById("label").style.display="none"; clearTimeout(tim); } function startTimer() { tim = setTimeout("hideMessage()",3000); } i did it using the above code.. but my problem is, i cant check it the second time, without reloading the page.. how to do it without refreshing the page and i want to add a bg color to that warning.. how to do that.. and, is there anyother way of doing it? any help is much appreciated.. and thanks so here is my "Project" for this class http://sw.cs.wwu.edu/~strickk/Project2/project2.html and here are the directions where im stuck at, just right click view source to see the code. I believe what i am doing wrong is where i enter my variables and i dont know how to get an alert message to pop up using an if statement as well as getting the values for the distances to show up correctly directions: 8. Now we will write some JavaScript to validate the input. We don’t want the user to be able to enter the same origin and destination city when they book a ticket. So we will use an if statement to check that. If they have entered the same origin and destination city then we will tell them that by using an alert statement and make them select again. All of your code to validate the input code goes in between the single quotes of the onClick event in the Calculate Fare button. Follow these steps: a) Assign the value of the origin city to a variable called origin Note that the value that gets assigned to origin is actually 0, 60, 90, 120 or 150 (and NOT Bellingham, Everett, Seattle etc.) since the value we gave to the each element of the list was its distance from Bellingham. This will make our lives easier later when we compute the fare. b) Assign the value of the destination city to a variable called destination in a similar fashion. c) Write an if statement that will test whether origin is equal to destination and if it is then do two things. i. Issue an alert message that says Please input different origin and destination cities ii. Stop the execution of the JavaScript code in the onClick event. Use return; as the second statement inside the if statement. Remember to use curly braces to denote that two statements are contained within the if statement. Your if statement will have the following structure to it. if (<put the test you want to do here>) { alert(<put the message here>); return; I'm wanting to put a piece of code on my website that will display when our next meeting will be. We have 2 meetings per month. I'm thinking what I need to do is create a code that gets the current month, day of month, and year then combines it together somehow, and if that combination is in a certain range a particular statement, "Next meeting is MM, DD YY." or "Next meeting is today." is displayed. If date is equal to or between 01012012 and 01112012, "Next meeting is January, 12 2012" is displayed. If date is equal to 01122012, "Next meeting is today" is displayed. If date is equal to or between 01132012 and 01252012, "Next meeting is January, 26 2012" is displayed. If date is equal to 01262012, "Next meeting is today" is displayed. ...that kind of thing. How would I combine the month, day of month, and year? Would 48 if statements be what I need to do? Sorry, I'm pretty new to javascript. If there's a better way to do this, please let me know. Thanks, CJ Hi, I'm using HTA with iframes contains external web pages, lot of pages (external - not mine) contains errors and while running 'script error' pops. If running the same pages in IE there are only error notice in the bottom left side of the browser. Can I do something to ignore those script error popups in my HTA? (I'm using also Javascript for my HTA) Could I use javascript code to stop Internet Explorer script error messages? Regards Bob Hi, Could I use javascript code to stop Internet Explorer script error messages? Bob Kuspe Hi all, I have an issue that seems to relate to IE6 only. Tested and working in IE8 and FF3. If you go to the following page and click 'Buy Now' at the bottom of the page to submit the form the jQuery validate library error messages are displayed at the top of the page, rather than next to the corresponding form element: http://bit.ly/cc97GP Any help appreciated with this one. Seems to work fine in IE8 and FF3 as mentioned. Best Regards, Picco I am developing a messaging service between members of my site. I am developing this with asp.net mvc. When a user goes to the SendMessage view to send a message to another member, there is a dropdown list which presents the sender with all the members of the site, which he or she will pick as the recipient. However, i don't want it to be a dropdown, i want it to be a text box, where a user types in the first couple of letters of a name, and the dropdown appears then with only the members which have the same couple of letters. This is basically like every email system out there (facebook and gmail have it just like that). And after they chose one, they can select another one in the same textbox, just separated by a comma or something like that. Basically, how do i achieve that in javascript? I'm not even sure what that functionality is called, that's why i had to explain it properly. Any help is greatly appreciated. thank you I apologize for all the text I'm about to type, but I just want to make sure I explain my problem in detail. So I have created a simple Weather Forecast algorithm containing the JavaScript code that uses a prompt to allow a user to enter a temperature in degrees Celsius, and based on the degrees entered (temperature scale is below), the program will display one of the following messages based on the selection structure I have created: (Kindly find attached .txt file of my entire code, I wasn't able to upload an HTML file.) -18 degrees Celsius: "Bundle up! It's freezing out there!" -18 - 0 degrees Celsius: "Pretty cold with a chance of snow!" 15 degrees Celsius: "Don't forget your jacket. It's still chilly out!" 16 - 27 degrees Celsius: "Perfect, lovely weather... unless it rains." 28 - 35 degrees Celsius: "Nice and warn. Go for a swim." 35 degrees Celsius: "Really hot! Best to stay in air conditioning." HELP Now i want improve on the same program and let the user enter the degrees in either unit using a prompt to ask the user whether the entry is Celsius(C) or Fahrenheit (F) (F scale is below) and use the correct degree breakdown to display the same messages: Less than 0 degrees Fahrenheit: "Bundle up! It's freezing out there!" 0 - 32 degrees Fahrenheit: "Pretty cold with a chance of snow!" 33 - 59 degrees Fahrenheit: "Don't forget your jacket. It's still chilly out!" 60 - 80 degrees Fahrenheit: "Perfect, lovely weather... unless it rains." 81 - 95 degrees Fahrenheit: " Nice and warn. Go for a swim." Greater than 95 degrees Fahrenheit: " Really hot! Best to stay in air conditioning." I'd appreciate if anyone can help me with this. Again, I've attached my original file where the user can only enter in degrees Celsius and gets the corresponding messages. I have tested it and it works perfectly. Attached Files hourlyForecast1.txt (954 Bytes, 24 views) hi people I'd need a program just in command prompt to post messages on server minecraft, possibly being able to automate this process every few time, should I use it for more players at a time, work done to pay 20 Euros or more p.s is nothing illegal I have been searching for a long time but have been unsuccessful on how to develop a drop down menu but have the menu items show in a list above the main nav. Not below. I really like the way this functions: http://www.sohtanaka.com/web-design/examples/toggle/ But I would like the item in the list to appear above the main nav so it animates up not down. Can anyone help me on how to alter this js code to perform this task? Here is the jQuery file link: http://code.jquery.com/jquery-latest.js I tried going through this js file but it very complex. Can anyone tell me what I need to change to have the animation roll up instead of down? Any help would be most appreciated. Hello everyone! So, what it does: You can successfully drag something anywhere, but when you click it again, it resets to its original position (I don't know why), and when you try to drag it again, as soon as your cursor touches the object it disappears (I don't know why). I'm hoping someone can tell me why it is happening and how to fix it! Code: // JavaScript Document var posX; var posY; var element; function drag(event) { element = document.getElementById("square"); posX = event.clientX; posY = event.clientY; element.addEventListener("mousemove", move, false); } function move(event) { if (typeof(document.getElementById("square").mouseup) == "undefined") element.addEventListener("mouseup", drop, false); //Prevents redundantly adding the same event handler repeatedly element.style.left = event.clientX - posX + "px"; element.style.top = event.clientY - posY + "px"; } function drop() { element.removeEventListener("mousemove", move, false); element.removeEventListener("mouseup", drop, false); } the html is a simple (position is set to relative): <p id="square" onmousedown="drag(event)">meep</p> Lastly, and most importantly, thank you all for your time =] EDIT: This is the first time I've written javascript code and would like to learn the basics, which is why I am not using a library. Hello there, CodingForums.com! I'm a newbie to Javascript, HTML, XHTML, CSS-- and oh god, everything, so please bear with me! I have come to understand that to get any better, I'll need support. I hope you guys (and gals) can assist! Here is my issue: I'm currently trying to develop a first-draft calculator that will allow me to calculate some values for work and the way I want it requires me to do it with a pair of drop-downs. Take a look at it he http://www.projectvoid.co.uk/ I would like to select the first drop-down, on the left-hand side (Current Lighting Products -> Type of Lamp) and for the right-hand side to copy it's selected value (Energy Efficient Products -> Type of Lamp). Furthermore, it shouldn't interfere with the fact that I'm also using those values with my dependent drop-down, below (Wattage). The only piece of code I've found that might help is this: Code: function setSelect(name1, name2) { var select1 = document.forms.formname.elements[name1]; var select2 = document.forms.formname.elements[name2]; select1.selectedIndex = select2.selectedIndex; } I am also unsure how to utilize it. I look forward to your aid! Thank you in advance. Okay, I'm having some trouble getting my head around how to do this.. Code: <select> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> </select> <select> <option value="Rhino">Rhino</option> <option value="Bird">Bird</option> <option value="Rooster">Rooster</option> </select> <select> <option value="0202A">Rhino - Text</option> <option value="0203A">Rhino - Text2</option> <option value="0204A">Bird - Text1</option> <option value="0205A">Bird - Text2</option> <option value="0202B">Rhino - Text</option> <option value="0204B">Rhino - Text2</option> <option value="0204C">Rooster - Text1</option> <option value="0205C">Rooster - Text2</option> <option value="0206C">Rooster - Text3</option> </select> So say we had those three drop-downs. I'm looking to make it so that second drop-down only has options corresponding to a relationship between the first and the third drop-down. Example - if you select A in the first drop-down you only see Rhino and Bird in the second drop-down. If you select B you will only see Rhino in the second drop-down. Lastly, if you select C you will only see Rooster in the second drop-down. Just can't figure this out. >.< I know how to edit the CSS, and minute parts of the JavaScript code (for example; speed of the drop). The problem is, I had a massive amount of help making the Javascript side of the menu, and do not know how to edit it... I want the rules to still apply, where only one can be expanded at a time (one of the first drops, and then only one of the sub-drops). I noticed in the code, I can edit it so there can be more than one drop, but that would mean, the whole menu could be expanded Also, I want my sub-drops. to have different span colour than the main drop. but trhe links and such, (everything else about it) can be the same.... My live demo is here! Thank you for any help and/or advice in advance, Best Regards, Tim |