JavaScript - Correct Text For Displaying Remainder
Good evening. I'm very new to this, but very excited that I've gotten this code so close. I am trying to get the computer to determine if a number is even or not. This is what I have:
[CODE] <script type = "text/javascript"> <!-- var firstNumber; // first string entered by user var answer; // the division problem // read in first number from user as a string firstNumber = window.prompt("Enter an integer"); //how to get a remainder var answer = firstNumber / 2 if (answer > 1) { document.writeln(answer + ". This number is even."); } </script> The bottom part is the problem. I am able to code that if the answer is greater than one, then return the following text, however, I can't for the life of me figure how to say... if the remainder is zero. Thank you, Similar TutorialsBox 1 - Box 2 / Box 3 and i put a round off number so the decimals dont give a million numbers the problem is...the math is wrong now.... someone please help me fix this.. <!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> <title>Calc</title> <script type="text/javascript"> function calculate() { var one = document.getElementById("one").value*1; var two = document.getElementById("two").value*1; var three = document.getElementById("three").value*1; document.getElementById("answer").value=((one-two)/three); ; } </script> </head> <body> Enter Number 1 <br> <br><input type="text" id="one" /><hr>Enter Number 2<br><br><input type="text" id="two" /><br><br><hr>Enter Average number<br><br><input type="text" id="three" /><br><br><button onclick="calculate();">Calculate</button> <br id="result"></center></br> Total <input type="text" readonly="readonly" id="answer" /><br><br></center> </body> </html> </td> </tr> </table> </center> </body> </html> Hi there. I have a program that generates a random exam with digits 0 -9. I have managed to generate random symbols to appear inbetween each question and it now accepts an answer. What i need is that when a division sum is generated, i need another field beside the answer for the remainder. Here is the code: <!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"><!-- InstanceBegin template="/Templates/Brittanica Template.dwt" codeOutsideHTMLIsLocked="false" --> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- InstanceBeginEditable name="doctitle" --> <title>Untitled Document</title> <!-- InstanceEndEditable --> <!-- InstanceBeginEditable name="head" --> <style type="text/css"> <!-- .equals { color: #0F0; } --> </style> <!-- InstanceEndEditable --> <style type="text/css"> <!-- body { background-image: url(../Images/blackboard.jpg); } #Main_div { height: 700px; width: 680px; margin: auto; position: relative; top: auto; padding: 0px; } #header_div { height: 179px; width: 660px; position: relative; left: auto; top: auto; right: auto; bottom: auto; margin: auto; } #body_div { height: 550px; width: 660px; position: relative; margin: auto; } body,td,th { color: #FFF; } --> </style></head> <body> <div id="Main_div"> <div id="header_div"><img src="../Images/math.png" width="660" height="179" /></div> <!-- InstanceBeginEditable name="EditRegion3" --> <script language="javascript" type="application/javascript"> function runCode() { document.getElementById("txt_sum11").value = rndNumber(); document.getElementById("txt_sum12").value = rndNumber(); document.getElementById("txt_sum21").value = rndNumber(); document.getElementById("txt_sum22").value = rndNumber(); document.getElementById("txt_sum31").value = rndNumber(); document.getElementById("txt_sum32").value = rndNumber(); document.getElementById("txt_sum41").value = rndNumber(); document.getElementById("txt_sum42").value = rndNumber(); document.getElementById("txt_sum51").value = rndNumber(); document.getElementById("txt_sum52").value = rndNumber(); genOperators(); document.getElementById("hiddenField1").value = eval(document.getElementById("txt_sum11").value + document.getElementById("symbol1").value + document.getElementById("txt_sum12").value) document.getElementById("hiddenField2").value = eval(document.getElementById("txt_sum21").value + document.getElementById("symbol2").value + document.getElementById("txt_sum22").value) document.getElementById("hiddenField3").value = eval(document.getElementById("txt_sum31").value + document.getElementById("symbol3").value + document.getElementById("txt_sum32").value) document.getElementById("hiddenField4").value = eval(document.getElementById("txt_sum41").value + document.getElementById("symbol4").value + document.getElementById("txt_sum42").value) document.getElementById("hiddenField5").value = eval(document.getElementById("txt_sum51").value + document.getElementById("symbol5").value + document.getElementById("txt_sum52").value) } function rndNumber(){ var returnNumber; returnNumber = Math.floor(Math.random()*11); return returnNumber; } function validateCode(){ var val1 = document.getElementById("txt_answer1").value var val2 = document.getElementById("hiddenField1").value if (val1 == val2){ alert("First answer is correct") } var val1 = document.getElementById("txt_answer2").value var val2 = document.getElementById("hiddenField2").value if (val1 == val2){ alert("Second answer is correct") } var val1 = document.getElementById("txt_answer3").value var val2 = document.getElementById("hiddenField3").value if (val1 == val2){ alert("Third answer is correct") } var val1 = document.getElementById("txt_answer4").value var val2 = document.getElementById("hiddenField4").value if (val1 == val2){ alert("Fourth answer is correct") } var val1 = document.getElementById("txt_answer5").value var val2 = document.getElementById("hiddenField5").value if (val1 == val2){ alert("Fifth answer is correct") } } function genOperators(){ for (var i = 1 ; i <= 5 ; i++){ var operator = Math.floor(Math.random()*4)+1; var actualOp = ""; switch(operator){ case 1: actualOp = "+"; break; case 2: actualOp = "-"; break; case 3: actualOp = "/"; break; case 4: actualOp = "*"; break; } document.getElementById("symbol"+i).value = actualOp; } } </script> <style type="text/css"> <!-- body { background-color: #999; } body,td,th { font-weight: bold; color: #900; } --> </style> <form id="form1"> <center> <input type="button" name="btn_getNumber" value="Click here to begin" onclick="runCode()"/> </center><br/> <center> <input type="text" name ="txt_sum11" id="txt_sum11" /> <input name="symbol1" type="text" id="symbol1" size="1" maxlength="1" /> <input type="text" name ="txt_sum12" id="txt_sum12" /> <span class="equals">=</span> <input type="text" name ="txt_answer1" id="txt_answer1" /> <input type="hidden" name="txt_actualAnswer1" id="hiddenField1" /> </center><br/> <center> <input type="text" name ="txt_sum21" id="txt_sum21" /> <input name="symbol2" type="text" id="symbol2" size="1" maxlength="1" /> <input type="text" name ="txt_sum22" id="txt_sum22" /> <span class="equals">=</span> <input type="text" name ="txt_answer2" id="txt_answer2" /> <input type="hidden" name="txt_actualAnswer2" id="hiddenField2" /> </center><br/> <center><input type="text" name ="txt_sum31" id="txt_sum31" /> <input name="symbol3" type="text" id="symbol3" size="1" maxlength="1" /> <input type="text" name ="txt_sum32" id="txt_sum32" /> <span class="equals">=</span> <input type="text" name ="txt_answer3" id="txt_answer3" /> <input type="hidden" name="txt_actualAnswer3" id="hiddenField3" /> </center><br/> <center><input type="text" name ="txt_sum41" id="txt_sum41" /> <input name="symbol4" type="text" id="symbol4" size="1" maxlength="1" /> <input type="text" name ="txt_sum42" id="txt_sum42" /> <span class="equals">=</span> <input type="text" name ="txt_answer4" id="txt_answer4" /> <input type="hidden" name="txt_actualAnswer4" id="hiddenField4" /> </center><br/> <center><input type="text" name ="txt_sum51" id="txt_sum51" /> <input name="symbol5" type="text" id="symbol5" size="1" maxlength="1" /> <input type="text" name ="txt_sum52" id="txt_sum52" /> <span class="equals">=</span> <input type="text" name ="txt_answer5" id="txt_answer5" /> <input type="hidden" name="txt_actualAnswer5" id="hiddenField5" /> </center><br/> <center> <p> <input type="button" name="btn_submit" value="Submit Answers" onclick="validateCode()"/> </p> </center> </form> <!-- InstanceEndEditable --></div> </body> <!-- InstanceEnd --></html> I also need to know how i would display all of the results of the test. For example "You got - 5 out of 5" "Time Taken - 3 minutes" "Date - 24-06-2011" Thank you. Hi again For instance I want to display some announcements from an external text file on a predefined box, like lets say 140 wide and height scalable according to text. The texts would be some announcements from me, a few words. I want the text justified and with previous / next link, if possible. And when they navigate to another page, they will get a random message in that box. There are news tickers on the net, but I just want something simple like this, no scrolling, fading, etc.. Has anyone a clue how I can accomplish that? Thanks. I've got this code, and nothing happens when I click the button! Please help. <!DOCTYPE HTML> <html> <head> <title> Author Identifier </title> </head> <body> <form action="w3schools.com" id="theForm"> <textarea name="input1" id="input1" rows=8 cols=80>Enter a passage from an author of your choice.</textarea> <br> <textarea name="input2" id="input2" rows=8 cols=80>Enter another passage from an author of your choice.</textarea> <br> <textarea name="input3" id="input3" rows=8 cols=80>Enter a third passage from an author of your choice.</textarea> <br> <br> <br> <textarea name="input5" id="input5" rows=8 cols=80>Enter a passage from a second author of your choice.</textarea> <br> <textarea name="input6" id="input6" rows=8 cols=80>Enter another passage from the second author of your choice.</textarea> <br> <textarea name="input7" id="input7" rows=8 cols=80>Enter a third passage from the second author of your choice.</textarea> <br> <br> <br> <textarea name="input8" id="input8" rows=8 cols=80>Enter a passage from a third author of your choice.</textarea> <br> <textarea name="input9" id="input9" rows=8 cols=80>Enter another passage from the third author of your choice.</textarea> <br> <textarea name="input10" id="input10" rows=8 cols=80>Enter a third passage from the third author of your choice.</textarea> <br> <br> <textarea name="Author1" id="Author1" rows=4 cols=40>Enter the first author's name.</textarea> <br> <textarea name="Author2" id="Author2" rows=4 cols=40>Enter the second author's name.</textarea> <br> <textarea name="Author3" id="Author3" rows=4 cols=40>Enter the third author's name.</textarea> <br> <br> <textarea name="input4" id="input4" rows=8 cols=80>Enter the passage by the author to be determined.</textarea> <br> <input type="button" id="button" name="button" onClick="allThatStuff()" value="Determine the Author!"> <br> <textarea name="Output" id="Output" rows=4 cols=40 readonly></textarea> </form> <script type="text/javascript"> var form = document.getElementById("theForm"); form.input4.onclick = function( ) { var Author1 = form.Author1.value var Author2 = form.Author2.value var Author3 = form.Author3.value var TextInput = form.Input1.value; var TextInput0 = form.Input2.value; var TextInput1 = form.Input3.value; var TextInput2 = form.Input5.value; var TextInput3 = form.Input6.value; var TextInput4 = document.form.Input7.value; var TextInput5 = form.Input8.value; var TextInput6 = form.Input9.value; var TextInput7 = form.Input10.value; var TextInput8 = form.Input4.value; var sentences = TextInput.split("."); var sentences0 = TextInput0.split("."); var sentences1 = TextInput1.split("."); var sentences2 = TextInput2.split("."); var sentences3 = TextInput3.split("."); var sentences4 = TextInput4.split("."); var sentences5 = TextInput5.split("."); var sentences6 = TextInput6.split("."); var sentences7 = TextInput7.split("."); var sentences8 = TextInput8.split("."); var SentencesPerText = sentences.length var SentencesPerText0 = sentences0.length var SentencesPerText1 = sentences1.length var SentencesPerText2 = sentences2.length var SentencesPerText3 = sentences3.length var SentencesPerText4 = sentences4.length var SentencesPerText5 = sentences5.length var SentencesPerText6 = sentences6.length var SentencesPerText7 = sentences7.length var SentencesPerText8 = sentences7.length var WordsTotal = 0; var WordsTotal0 = 0; var WordsTotal1 = 0; var WordsTotal2 = 0; var WordsTotal3 = 0; var WordsTotal4 = 0; var WordsTotal5 = 0; var WordsTotal6 = 0; var WordsTotal7 = 0; var WordsTotal8 = 0; for ( var i = 0; i < SentencesPerText; ++i ) { var sentence = sentences[i]; var words = sentence.split(" "); WordsTotal += words.length; } for ( var i = 0; i < SentencesPerText0; ++i ) { var sentence0 = sentences0[i]; var words0 = sentence0.split(" "); WordsTotal0 += words0.length; } for ( var i = 0; i < SentencesPerText1; ++i ) { var sentence1 = sentences1[i]; var words1 = sentence1.split(" "); WordsTotal1 += words1.length; } for ( var i = 0; i < SentencesPerText2; ++i ) { var sentence2 = sentences2[i]; var words2 = sentence2.split(" "); WordsTotal2 += words2.length; } for ( var i = 0; i < SentencesPerText3; ++i ) { var sentence3 = sentences3[i]; var words3 = sentence3.split(" "); WordsTotal3 += words3.length; } for ( var i = 0; i < SentencesPerText4; ++i ) { var sentence4 = sentences4[i]; var words4 = sentence4.split(" "); WordsTotal4 += words4.length; } for ( var i = 0; i < SentencesPerText5; ++i ) { var sentence5 = sentences5[i]; var words5 = sentence5.split(" "); WordsTotal5 += words5.length; } for ( var i = 0; i < SentencesPerText6; ++i ) { var sentence6 = sentences6[i]; var words6 = sentence6.split(" "); WordsTotal6 += words6.length; } for ( var i = 0; i < SentencesPerText7; ++i ) { var sentence7 = sentences7[i]; var words7 = sentence7.split(" "); WordsTotal7 += words7.length; } for ( var i = 0; i < SentencesPerText8; ++i ) { var sentence8 = sentences8[i]; var words8 = sentence8.split(" "); WordsTotal8 += words8.length; } var Author1Name = form.Author1.value var Author2Name = form.Author2.value var Author3Name = form.Author3.value var WordsPerSentence = WordsTotal/SentencesPerText var CharsTotal = TextInput.replace(/[\s\.]/g).length; var WordsPerSentence0 = WordsTotal0/SentencesPerText0 var CharsTotal0 = TextInput0.replace(/[\s\.]/g).length; var WordsPerSentence1 = WordsTotal1/SentencesPerText1 var CharsTotal1 = TextInput1.replace(/[\s\.]/g).length; var WordsPerSentence2 = WordsTotal2/SentencesPerText2 var CharsTotal2 = TextInput2.replace(/[\s\.]/g).length; var WordsPerSentence3 = WordsTotal3/SentencesPerText3 var CharsTotal3 = TextInput3.replace(/[\s\.]/g).length; var WordsPerSentence4 = WordsTotal4/SentencesPerText4 var CharsTotal4 = TextInput4.replace(/[\s\.]/g).length; var WordsPerSentence5 = WordsTotal5/SentencesPerText5 var CharsTotal5 = TextInput5.replace(/[\s\.]/g).length; var WordsPerSentence6 = WordsTotal6/SentencesPerText6 var CharsTotal6 = TextInput6.replace(/[\s\.]/g).length; var WordsPerSentence7 = WordsTotal7/SentencesPerText7 var CharsTotal7 = TextInput7.replace(/[\s\.]/g).length; var WordsPerSentence8 = WordsTotal7/SentencesPerText7 var CharsTotal8 = TextInput7.replace(/[\s\.]/g).length; var inputAverage11 = (CharsTotal + CharsTotal0 + CharsTotal1 + sentences.length + sentences0.length + sentences1.length + WordsTotal + WordsTotal0 + WordsTotal1 + WordsPerSentence + WordsPerSentence0 + WordsPerSentence1); var inputAverage21 = (CharsTotal2 + CharsTotal3 + CharsTotal4 + sentences2.length + sentences3.length + sentences4.length + WordsTotal2 + WordsTotal3 + WordsTota4 + WordsPerSentence2 + WordsPerSentence3 + WordsPerSentence4); var inputAverage31 = (CharsTotal5 + CharsTotal6 + CharsTotal7 + sentences5.length + sentences6.length + sentences7.length + WordsTotal5 + WordsTotal6 + WordsTotal7 + WordsPerSentence5 + WordsPerSentence6 + WordsPerSentence7); var inputAverage1 = (inputAverage11 / 12); var inputAverage2 = (inputAverage21 / 12); var inputAverage3 = (inputAverage31 / 12); var input4 = (CharsTotal8 + sentences8.length + WordsTotal8 + WordsPerSentence8); var no = "no" var yes = "yes" for (i = 0; i < 15; ++i) {if input4 = (inputAverage1 + i) {var Author1="yes" var Author1Off = i } ++i } var j = 0 while(j<15) {if input4 = (inputAverage1 - i) {var Author1="yes" var Author1Off = i } ++j } var i = 0 while(i<15) {if input4 = (inputAverage2 + i) {var Author2="yes" var Author2Off = i } ++i } var j = 0 while(j<15) {if input4 = (inputAverage2 - i) {var Author2="yes" var Author2Off = i } ++j } var i = 0 while(i<15) {if input4 = (inputAverage3 + i) {var Author3="yes" var Author3Off = i } ++i } var j = 0 while(j<15) {if input4 = (inputAverage3 - i) {var Author3="yes" var Author3Off = i } ++j } if (Author1 = yes) { if (Author2 = yes) { if (Author3 = yes) { if (Author1Off < Author2Off) { if (Author1Off < Author3Off) { form.Output.value = (Author1Name + " is the author!") } else { form.Output.value = (Author3Name + " is the author!") } } else if (Author2Off < Author3Off) { form.Output.value = (Author2Name + " is the author!") } else { form.Output.value = (Author3Name + " is the author!") } } else if (Author1Off < Author2Off) { form.Output.value = (Author1Name + " is the author!") } else { form.Output.value = (Author2Name + " is the author!") } } else if (Author3 = yes) { if (Author1Off < Author3Off) { form.Output.value = (Author1Name + " is the author!") } else { form.Output.value = (Author3Name + " is the author!") } } else { form.Output.value = (Author1Name + " is the author!") } } else if (Author2 = yes) { if (Author3 = yes) { if (Author3Off < Author2Off) { form.Output.value = (Author3Name + " is the author!") } else { form.Output.value = (Author2Name + " is the author!") } } else { form.Output.value = (Author2Name + " is the author!") } } else if (Author3 = yes) { form.Output.value = (Author3Name + " is the author!") } else { form.Output.value = "The author was unable to be determined." } } </script> </body> </html> Reply With Quote 01-16-2015, 02:53 PM #2 sunfighter View Profile View Forum Posts Senior Coder Join Date Jan 2011 Location Missouri Posts 4,830 Thanks 25 Thanked 672 Times in 671 Posts Please use code tags and put your code in them. It makes it easier on every one. Your input button calls the function allThatStuff(). Code: <input type="button" id="button" name="button" onClick="allThatStuff()" value="Determine the Author!"> But you do not have a function by that name. You only have a single function named Code: form.input4.onclick = function(){.....} But even getting that straight wont work when you have things like: Code: if input4 = (inputAverage2 + i){ var Author2="yes" var Author2Off = i } the if statement S/B Code: if ( input4 == (inputAverage2 + i) ) {....} I'm very new at JavaScript and I'm trying to get each of the if statements below in a text text box with the result depending on the answer of the equation. However i can't figure out a way to allow the user to click a button to to show the result in a text box. If anyone could help it would be much appreciated. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <script type="text/javascript"> function calculate() { A = document.form1.text2.value B =(parseInt(A ) * 52) D= (parseInt(B ) * 0.015 ) if ( B <= 6000){ tax = 0;} else if (B <= 37001){ tax = (B - 6000) * .15; } else if (B<= 80001){ tax = (B - 37000) * .30 + (37000 - 6000) * .15; } else if (B <= 180001){ tax = (B- 80000) * .37 + (80000- 37000) * .30 + (37000 - 6000) * .15; } else tax = (B - 180000)* .45 + (180000 - 80000 begin_of_the_skype_highlighting**************180000 - 80000******end_of_the_skype_highlighting) * .37 + (80000- 37000) * .30 + (37000 - 6000) * .15;} </script> </HEAD> <BODY> <form name="form1"> Weekly Salary: <INPUT TYPE="TEXT" NAME="text2"> <INPUT TYPE="BUTTON" VALUE="SUBMIT" Onclick="calculate();"> </BODY> </HTML> hi all, I have a simple website with 2 Frames, In top frame I have a button that invokes CGI script and internally that CGI script prints info (text) into the bottom frame. Going further we want to print the output coming from CGI into a textarea object in bottom form. I have a function in my CGI script: But ends up printing multiple textarea objects in lower frame. We want to print each line of text into the same textarea object in lower frame. and at the end display a new button. How can we do this using javascript/CGI? I tried the following but not displaying anything. sub print_message { my($message1, $message2) = @_; my $final_message = $message1 . " " . $message2; print <<END_HTML; <html> <head> <form name="myform"> <table border="0" cellspacing="0" cellpadding="5"> <tr> <td><textarea name="outputtext" rows="10" cols="100"> $final_message </textarea> </td> </tr> </table> </form> <style> <!-- a{font-weight:bold;font-family:arial;text-decoration:underline;font-size:13px;} a:hover{font-weight:bold;font-family:arial;text-decoration:none;font-size:13px;} // --> </style> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <a href="main.html" rel="nofollow" target="bottom"></a> <title>CTS Debug Information</title> <style type="text/css"> img {border: none;} </style> </head> <body> </body> </html> END_HTML I created this function in javascript: <script language="javascript" type="text/javascript"> function addtext() { var newtext = document.myform.outputtext.value; var nextLineTextNode = document.createTextNode(newtext + "\r\n"); var logData = document.getElementById("outputtext"); logData.appendChild(nextLineTextNode); logData.scrollTop = logData.scrollHeight - logData.clientHeight; } </script> But when i implemented in my CGI nothing is printed. Thanks!!! I have a need to display, edit and save the contents of a text area to a text file or what ever is best suited, directly to the website root or folder within the root of the site. Is there anyway this can be done with out database software? As I dont have the option to install mysql or any other software to the webserver. Any help would be greatly appreciated. Thx Just a little backround: The webserver is acually an open source linux firewall which i was able to edit the apache config file to host a second site. I just want the ability to store edit and display some network information within a very small site I made without the use of a database. Is this even possible? I'm using the script below in a custom HTML to generate a random line of text (not with the text shown here). This works fine BUT; I want it to go randomly through the WHOLE list without repeating lines that already have been printed. As it is now, a line of text might be printed several times in a row, which is a little annoying. I'm using a refresh button for generating a new line of text. Alternatively, How can I just make it display in the order shown and just re-arrange the content so it seems random to the user? Random would the best though... Any ideas?? : ) Code: <script language="JavaScript"> <!-- var r_text = new Array (); r_text[0] = "All the leaves are brown"; r_text[1] = "And the sky is grey"; r_text[2] = "I've been for a walk"; r_text[3] = "On a winter's day"; r_text[4] = "I'd be safe and warm"; r_text[5] = "If I was in L.A."; r_text[6] = "California dreaming, On such a winter's day"; var i = Math.floor(7*Math.random()) document.write(r_text[i]); //--> </script> Ahoy, Lemme try to explain this as best as I can. Bullet points might help: When someone clicks on an image here (http://gta.kwivia.co.uk/gta-iv/), the rest of the images collapse and become invisible Below the image, some links appear Also, there will be a "show other images" button which will then show the rest of the images http://gta.kwivia.co.uk/gta-iv/ I will appreciate all solutions to this problem. If you need to know anything, simply ask me. Ok so i have wrote some code which can be seen he http://www.runningprofiles.com/members/include/test.php This works great but when i add the code to the page i want it on (include "include/test.php" for some reason the code does not work... the text is delayed and then lags behind the images.. this can been seen here http://www.runningprofiles.com/members/ I have no idea why its happening! Code for the code is Code: <html> <head> <title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q__26659912.html</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script> <script type="text/javascript"> function advance() { $("#slideshow").cycle("next"); cycleCaption(); } var displayedIndex = 0 function cycleCaption() { $("#caption").children().each( function(index) { $(this).css("font-weight", (index==displayedIndex)? "bold" : "normal" ); }); displayedIndex = (++displayedIndex==$("#caption").children().length)? 0 : displayedIndex; } $(function() { $("#slideshow").cycle({ timeout: 0 }); $("img").each( function() { $("<div />").html($(this).attr("title")).appendTo($("#caption")); }); cycleCaption(); setInterval( "advance()", 2000 ); }); </script> </head> <body> <div id="slideshow" style="float: left;"> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14882_jruqg6x4uu6frw2g872b.jpg" title="Aisling Cuffe Before Foot Locker" /> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14879_mzcgn05auhs24fnsygc1.jpg" title="Foot Locker Ballerness" /> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14880_u1npsmglw7b9t6hmoqhu.jpg" title="Foot Locker The Rocket" /> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14887_9bblfhhvc0x66vebgjua.jpg" title="NCAA D2 Cro" /> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14884_mud4ewe6uh6ihrrpux6g.jpg" title="NXN Recap and Results" /> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14865_y1kt8vzejkvz25k075x2.jpg" title="Give Your " /> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14877_1mlnygbenofquj5h3mcz.jpg" title="NCAA D2 XC Champ" /> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14855_9g971maove1jyos0h9zk.jpg" title="Defending" /> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14850_6u22ylfzym7sxq1zw8p8.jpg" title="NXN 121" /> </div> <div id="caption" style="float: left;"> </div> </body> </html> Can anyone tell me what I have done wrong here? I have the following html code Code: <div id='group1'> <tr class='time'> <td colspan='3' name='1262815200'></td> </tr> <tr> <td class='timeleft group1' name='1262815200' colspan='3'></td> </tr> <tr class='game'> <td><input type='radio' name='G1' value='NYJ'>NYJ</td> <td><input type='radio' name='G1' value='BUF'>BUF</td> <td><select name='G1P' class='points' tabindex = '1'></select></td> </tr> </div> and when I use the selector $('#group1 input) it does not select anything (namely the inputs in this code). But when I use the selector $('div input') it will select them (and more on the page which I don't want). Is anyone able to see what I have done wrong? I've tried everything I can think of in terms of testing, and I have narrowed it down to the selector. Thanks. Does anyone know why I am not getting an alert on an empty form INPUT value? Code: if (document.forms["form"]["targetname"].value == "" && document.forms["form"]["unknownname"] == false) { alert ("What ever"); return false; } document.forms["form"]["targetname"] is a form INPUT text document.forms["form"]["unknownname"] is a form INPUT checkbox I suspect the problem is due to 'false'.. but I can't figure out why. How can I change the day when the user select a month? When they select Feb ->29 days, select May -> 31 days. Like what facebook does. I found and am using the following script to add checkbox values to a textarea. Code: <script type="text/javascript"> function add_sub(el){ if (el.checked) el.form.elements['type'].value+=el.value; else{ var re=new RegExp('(.*)'+el.value+'(.*)$'); el.form.elements['type'].value=el.form.elements['type'].value.replace(re,'$1$2'); } } </script> </head> <body> <form name="form1" method=post> <textarea name="type" rows="5" cols="35" onclick="this.focus();this.select();"> </textarea><br> <input type="checkbox" name="bob" id="bob" value="<p>" onclick="add_sub(this);"><label for="bob"><p></label><br> <input type="checkbox" name="bob1" id="bob1" value="<span>" onclick="add_sub(this);"><label for="bob1"><span></label><br> <input type="checkbox" name="bob2" id="bob2" value="<div>" onclick="add_sub(this);"><label for="bob2"><div></label> That is working. However, I wanted to put carriage returns after each checkbox value added, so I added the + "\r\n" as follows: Code: <script type="text/javascript"> function add_sub(el){ if (el.checked) el.form.elements['type'].value+=el.value + "\r\n"; else{ var re=new RegExp('(.*)'+el.value+'(.*)$'); el.form.elements['type'].value=el.form.elements['type'].value.replace(re,'$1$2'); } } </script> That is working when adding the value, but removing the value when the checkbox is unchecked is not working. I know the regular expression, etc. needs to be updated to account for the carriage returns, but I have tried everything I can think of and cannot get it to work. Help correcting the code is appreciated. I have tried many ways to do this and have also searched the forum, no go. I was doing it manually doing this: Code: Math.round((#)*100)/100 But no go, so I found this function here on the forum: Code: function roundNumber(num, dec) { var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec); return result; } No go, it works yes, don't get me wrong. But I am working on a invoicing system and it needs to be exact. For instance with this number: Quote: 0.27470000001 It returns 0.27, when in reality it should return 0.28 because of the 7 changes the 4 to 5 and then 5 changes the 7 to 8. But it doesn't work. While reading some things I found while searching google I see that Math.round doesn't work 100% the way it should mathematically. So what options do I have left, I can't believe that a simple rounding calculationg that excel can do ha ha JS cannot. Which of these is the correct way to set the className attribute, or are they both okay? option 1: Code: var t = document.createElement("p"); t.className = "myclass"; option 2: Code: var t = document.createElement("p"); t.setAttribute("class","myclass"); Hello coding forum users, I am working on the only javascript chapter of my HTML textbook. It asks me to: Quote: replace the line <img id="sky" src="sky0.jpg" alt=""/> with a script element that writes the following HTML code: <img id='sky' src='mapNum.jpg' alt=' ' /> where mapNum is the value of the mapNum variable. so I try PHP Code: <script type="text/javascript" /> document.write("<img id='sky' src='mapNum.jpg' alt=' ' />") </script> after a few other attempts I search codingforums and find: PHP Code: document.write("<img id=\"sky\" src='sky"+mapNum+".jpg' alt='' />"); and PHP Code: document.write('<img id="sky" src="sky'+mapNum+'.jpg" alt="" />'); and these work perfectly fine but I don't understand why? my textbook only has one javascript chapter and its really small and vague, and my teacher hasn't answered my emails, so I would be grateful if anyone can tell my why my first code falls flat. Hi, I'm trying to figure out how to make this work and I'm stumped. I wrote this code: <script type=text/javascript> function firstfunction(); { if(document.form1.inputnumbers.value="55"); { document.form1.outputstate.value="this is a number"; } else if { document.form1.inputnumbers.value="never"; } { document.form1.outputstate.value="this is a number"; } else { document.form1.outputstate.value=""; } </script> <form name="form1" method="post"> <input type="text" id="inputnumbers" name="inputnumbers";> <input type="button"; value="Enter"; onclick="firstfunction()"><br><br> <textarea id="outputstate"; name="outputstate"; cols=60; rows=10; style="border:1"; readonly;> I'm trying to doing something really simple but I can't seem to make it work. I'm trying have the textarea display a certain message depending on if the first input box says a certain word or number. So like in the code, if the user types "55" or "never" in the first box, then the second box should say a certain message. Then I used the else statement so that if "55" or "never" is not entered, then the second box says nothing. If you can spot my error or suggest a different way of going about writing the code, it would be very much appreciated. Thank you. Whats wrong with the code below? I'm trying to get the email service provider name. Code: <html> <head> <script type="text/javascript"> function GetProvider { var fullemail = openinviter.email_box.value; var afterat = fullemail.split("@"); var Provider = afterat[1].split("."); var showit = Provider[0]; openinviter.provider_box.value=showit; } </script> </head> <body> <form action="" method="post" name="openinviter"> <input type="text" name="email_box" onchange="GetProvider()" /> <input type="text" name="provider_box" value=""> </form> </body> </html> Thanks alot! i am making a simple multiple choice quiz and if user gets all correct i need it to automatically go to a new page rather than having a manual button for that so they cant move on until all questons are answered correctly. Most reatful for anyhelp!!!!!! Thanks Code: <SCRIPT Language ="JavaScript"> function ValidateForm(){ result = new Array(); count = 0; if (!document.forms[0].one[3].checked == true) { result[count] = "Question 1. The correct answer is " + document.forms[0].one[3].value + "."; count++; } if (!document.forms[0].two[0].checked == true) { result[count] = "Question 2. The correct anwser is " + document.forms[0].two[0].value + "."; count++; } if (!document.forms[0].three[3].checked == true) { result[count] = "Question 3. The correct answer is " + document.forms[0].three[3].value + "."; count++; } if (!document.forms[0].four[3].checked == true) { result[count] = "Question 4. The correct answer is " + document.forms[0].four[3].value + "."; count++; } if (result.length > 0) { var vString = ""; for (var i=0; i<result.length; i++) { vString = vString + result[i] + "\n"; } alert(result.length + " incorrect answers:\n" + vString); return(false); } else { alert("All of the questions were answered correctly."); return(true); } } function MM_goToURL() { //v3.0 var i, args=MM_goToURL.arguments; document.MM_returnValue = false; for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'"); } </SCRIPT> |