JavaScript - If Not Blank Then Run Script?
Hi,
in my code I am checking a form field against a database Code: <script type="text/javascript"> $(document).ready(function() { $("#DiscountCode").blur(function() { //remove all the class add the messagebox classes and start fading $("#msgbox").removeClass().addClass('messagebox').text('Checking code...').fadeIn("slow"); //check the username exists or not from ajax $.post("check-code.php",{ DiscountCode:$(this).val() } ,function(data) { if(data=='no') //if username not avaiable { $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox { //add message and change the class of the box and start fading $(this).html('<img src="resources/images/tick.png" /> Code matched!').addClass('messageboxok').fadeTo(900,1); }); } else { $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox { //add message and change the class of the box and start fading $(this).html('<img src="resources/images/cross.png" /> Sorry, code incorrect!').addClass('messageboxerror').fadeTo(900,1); }); } }); }); }); </script> <p> <label>Discount code</label> <input class="text-input small-input" type="text" id="DiscountCode" name="DiscountCode" /> <span id="msgbox" style="display:none"></span> </p> I would only like this code to run if the form field is not blank please help?! thanks Similar TutorialsThanks for reading. I believe this is a JavaScript question, but if not, let me know and I'll move to another heading. I'd like a script that would allow a user to complete a sentence in a maximum of 140 characters (we'll let Twitter set the standard) and then rotate each users output on the screen. I also need to capture a name and email address. Example: "A man is _______________" Name________________ Email ________________ Output (to be displayed and rotated above the form) A man is a friend. I believe a HTML form will capture the info, but I'm unclear on how to have the output and name appear on the same screen and rotate between responses. Many Thanks. A PHP/JS application that runs fine on the live server misbehaves on localhost. All the prefilled fields are showing empty. Any help would be appreciated. Thanks. Will update the thread with the code soon. Please let me know if there is a configuration error or general JS error. One error I get is something like : "Object does not support this method " or so.... Pls help Hello all, First time back here in a while, but I'm trying to get proficient in JS. I want to make my input element reset its value attribute to blank, which is originally set to "your e-mail". You know the effect you see on forms that have text in them, then with the onclick attribute, you can clear the text in the box. So, after looking around trying to find out what to do, here's what I've attempted. HTML Code: <form id="emailbox" name="form1" method="post" action=""> <div> <input type="text" name="go" id="go" value="your e-mail" onclick="removeText()"/> <input type="submit" value="Join" /> </div> </form> JS: Code: <script type="text/javascript"> function removeText(){ var form = document.getElementById['emailbox']; var name = form.elements['go'].value; } </script> What do I do next to complete my objective? Hello, I have a three field contact form on an HTML5 page. Using CSS3/HTML5 techniques, the fields change state as the info is entered properly (green OK symbol if good, red "!" if not, etc). That all works as expected in all browsers. My final hurdle is preventing the form being submitted with nothing entered in the fields. I have done hours of research and have tried several ways of writing the checkFeedbackForm function. My problem is that none of the solutions I've found are recognized by FireFox (mac and pc) and IE. They just ignore the javascript and allow the empty form to be emailed. Here is the code that is checking the fields: Code: <script type="text/javascript"> function checkFeedbackForm(form){ if(form.fullname.value=='') { alert('Please enter your Name'); form.fullname.focus(); return false; } if(form.email.value=='') { alert('Please enter a valid Email address'); form.email.focus(); return false; } if(form.message.value=='') { alert('Please tell me a little bit about your ideas.'); form.message.focus(); return false; } return true; } </script> Here is my form: Code: <form id="signup" action="mailinfo.php" method="post" onSubmit="return checkFeedbackForm(this);" > <input type="hidden" name="returnURL" value="thankyou.html" /> <fieldset><ol> <li><label for="fullname">Name</label> <input type="text" id="fullname" name="fullname" placeholder="Your name" required /></li> <li><label for="email">Email</label> <input type="email" id="email" name="email" placeholder="Your email" title="Please enter a valid email" required /></li> <li><label for="message">Message</label> <textarea id="message" name="message" cols="32" rows="8" placeholder="Your message" required /></textarea></li></ol> </fieldset> <input type="submit" value="Send It" /> <div class="privacy">Your information is for our project only and will not be shared or sold. Promise.</div> </form> Through experimentation, I have found that removing the ID from the form allows the javascript to function in all browsers, but that kills my form styling. I think it will be easier to fix the javascript than redo my CSS. This may be obvious, but I'm not a programmer. I'm a designer who muddles through on small scale stuff like this. Any help is greatly appreciated. Thanks. Does anyone know how I can modify the code below to show a question that has more then one fill in the blank? For example: _____ is an attitude or behavior which leads another to do ________. Thank you. Code: <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript"> var question_type=new Array(4) question_type[0]="mult"; question_type[1]="mult"; question_type[2]="blank"; question_type[3]="blank"; var questions=new Array(4) questions[0]="The words used to <u>describe</u> the manifestation of Jesus as Messiah of Israel, Son of God and Savior of the world are ..."; questions[1]="Which of these is not a symbol of the Holy Spirit?"; questions[2]="Human life must be respected and protected absolutely from the moment of ______."; questions[3]="_____ is an attitude or behavior which leads another to do evil."; var answers = new Array(4) answers[0]= "B"; //The Epiphany answers[1]= "C"; //Sunshine [water, fire, anointing] answers[2]="conception"; answers[3]="scandal"; var each_question = new Array(3) each_question[0]="<table width='98%' border='0'>" + "<tr>" + "<td colspan='2'>" + "<font face='Arial, Helvetica, sans-serif'>" + questions[0] + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%'>" + " " + "</td>" + "<td>" + " " + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='radio' name='choice' value='A'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "The creed" + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='radio' name='choice' value='B'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "The Epiphany" + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='radio' name='choice' value='C'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "The magisterium" + "</font>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='radio' name='choice' value='D'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "The Annunciation" + "</font>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + " " + "</td>" + "<td>" + "<img src='line_animation.gif' width='160' height='14' align='right'>" + "</td>" + "</tr>" + "</table>" + "</font>"; each_question[1]="<table width='98%' border='0'>" + "<tr>" + "<td colspan='2'>" + "<font face='Arial, Helvetica, sans-serif'>" + questions[1] + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%'>" + " " + "</td>" + "<td>" + " " + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='radio' name='choice' value='A'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "Water" + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='radio' name='choice' value='B'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "Fire" + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='radio' name='choice' value='C'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "Sunshine" + "</font>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='radio' name='choice' value='D'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "Anointing" + "</font>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + " " + "</td>" + "<td>" + "<img src='line_animation.gif' width='160' height='14' align='right'>" + "</td>" + "</tr>" + "</table>" + "</font>"; each_question[2] = "<table width='98%' border='0'>" + "<tr>" + "<td colspan='2'>" + "<font face='Arial, Helvetica, sans-serif'>" + questions[2] + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%'>" + " " + "</td>" + "<td>" + " " + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='text' name='text_field'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + " " + "</td>" + "<td>" + "<img src='line_animation.gif' width='160' height='14' align='right'>" + "</td>" + "</tr>" + "</table>" + "</font>"; each_question[3] = "<table width='98%' border='0'>" + "<tr>" + "<td colspan='2'>" + "<font face='Arial, Helvetica, sans-serif'>" + questions[3] + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%'>" + " " + "</td>" + "<td>" + " " + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='text' name='text_field'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + " " + "</td>" + "<td>" + "<img src='line_animation.gif' width='160' height='14' align='right'>" + "</td>" + "</tr>" + "</table>" + "</font>"; var currentQuestion=0; var score=0; function writeEachQuestion() { if(currentQuestion==0){ top.bottom_right.document.open(); top.bottom_right.document.write("<center>" + "<h3>" + "<font face='arial, helvetica, verdana'>" + "Go get 'em," + " " + userName + "!" + "<br>" + "</h3>" + "Let's see how well" + "<br>" + "you know your faith!" + "</center>" + "</font>"); top.bottom_left.document.write(each_question[currentQuestion]); } else { top.bottom_left.document.write(each_question[currentQuestion]); top.bottom_right.document.open(); } } function swapper() { top.bottom_left.document.fish_first.src="next2.gif"; } function unswapper() { top.bottom_left.document.fish_first.src="next.gif"; } function checkQuestionType() { if (question_type[currentQuestion-1]=="mult"){ multChecker(); } else if (question_type[currentQuestion-1]=="blank") { textChecker(); } } function multChecker() { var answerValue=answers[currentQuestion-1]; var checkedIndex = -1; for(i=0; i < top.bottom_left.document.quiz_questions.choice.length; i++) { //if a radio button is checked, the variable checkedIndex is set to the value of that index number. if(top.bottom_left.document.quiz_questions.choice[i].checked){ checkedIndex = i; selected_answer = top.bottom_left.document.quiz_questions[checkedIndex].value; } } if (selected_answer==answerValue) { score++; //The angelTableCorrect() function runs(see below). angelTableCorrect(); //An alert pops up if nothing's checked, with a string telling the user to guess next time. } else if (checkedIndex==-1){ alert("Next time," + " " + userName + "," + " " + "take a guess!"); //Because I'm heartless, the user isn't given a second chance. If not guess was made, angelTableWrong() executes (see below). angelTableWrong(); } else { angelTableWrong(); } } function textChecker() { var answerValue=answers[currentQuestion-1]; //theWord represents the user's input. var theWord = top.bottom_left.document.quiz_questions.text_field.value; theWordLower=theWord.toLowerCase(); if(theWordLower==answerValue) { score++; angelTableCorrect(); } else if (theWord!=answerValue) { angelTableWrong(); } } function angelTableCorrect () { top.top_right.document.open(); top.top_right.document.write("<table align='left'>" + "<tr>" + "<td align='center'>" + "<font face='Arial'>" + "Right," + " " + userName + "!" + "<br>" + "You're" + " " + score + " " + "out of" + " " + currentQuestion + "</td>" + "<td>" + "<img src='angel_correct.gif'>" + "</td>" + "</tr>" + "</table>"); } function angelTableWrong () { top.top_right.document.open(); top.top_right.document.write("<table align='left'>" + "<tr>" + "<td align='center'>" + "<font face='Arial'>" + "Wrong," + " " + userName + "." + "<br>" + "You're" + " " + score + " " + "out of" + " " + currentQuestion + "</td>" + "<td>" + "<img src='angel_wrong.gif'>" + "</td>" + "</tr>" + "</table>"); } function writeBeginning() { top.bottom_left.document.clear(); top.bottom_left.document.open(); top.bottom_left.document.write("<html>" + "<head>" + "</head>" + "<body>" + "<form name='quiz_questions'>"); } //This function writes the concluding part of each quiz question table in the bottom_left frame, except for the last one. //The last one's Next button has to call a different function, so I wrote the next function to do that. function writeEnding(){ top.bottom_left.document.write("<img name='fish_first' src='next.gif' align='right' onMouseOver='top.top_left.swapper();' onMouseOut='top.top_left.unswapper();' onMouseUp='top.top_left.onNext();'>" + "</form>" + "</body>" + "</html>") } //This function writes the concluding part of the last question, which has a next button that calls a //different function. function writeEndingLast(){ top.bottom_left.document.write("<img name='fish_first' src='next.gif' align='right' onMouseOver='top.top_left.swapper();' onMouseOut='top.top_left.unswapper();' onMouseUp='top.top_left.writeMailTable();'>" + "</form>" + "</body>" + "</html>") } function writeMailTable(){ top.top_right.document.open(); top.top_right.document.write("<font face='arial, verdana, helvetica'>" + "<center>" + "Thank you for" + "<br>" + "taking the quiz," + " " + userName + "!" + "<br><br>" + "</center>"); top.bottom_right.document.open(); top.bottom_right.document.write("<font face='arial, verdana, helvetica'>" + "<center>" + "If you don't have questions" + "<br>" + "you'd like to have answered," + " " + "<a href='http://www.archden.org' target='_blank')>" + "return to the" + "<br>" + "Archdiocese of Denver home page." + "</a>" + "</center>"); top.bottom_left.document.open(); top.bottom_left.document.write("<font face='arial, verdana, helvetica'>" + "Do you have questions about this quiz," + " " + userName + "?" + " " + "<img src='angel_final.gif' align='right'>" + "Post them in" + " " + "<a href='http://www.archden.org/ubb' target='_blank')>" + "The Upper Room," + "</a>" + " " + "the online community of the Archdiocese of Denver, in the 'What Does the Church Teach About ...?' forum!"); } function onNext() { //Write a table to the_questions.htm that includes a variable for the new question. if(currentQuestion==3) { currentQuestion++; textChecker(); doTheMath(); top.bottom_left.document.open(); top.bottom_left.document.write("<font face='arial, verdana, helvetica'>" + "<center>" + "You got" + " " + "<b>" + finalPercent + "%" + "</b>" + " " + "of the questions right," + " " + userName + "!" + "<br>" + "Click on the 'Next' fish" + "<br>" + "one more time to find out" + "<br>" + "how to get answers for those questions you missed." + "</center>" + "</font>"); writeEndingLast(); } else { currentQuestion++; checkQuestionType(); writeBeginning(); writeEachQuestion(); writeEnding(); } } //The doTheMath function divides the score by 20, and that multiplies that value by 100 to come up //with a final percentage value. That is used in the string written at the end (in the above onNext function). function doTheMath(){ thePercent=score/4; finalPercent=thePercent*100; } </script> </head> <body bgcolor="#FFFFFF" onLoad="writeBeginning(); writeEachQuestion(); writeEnding();"> <img src="title.gif" width="371" height="109"> <script language="JavaScript"> </script> </body> </html> Hello all, I would like someone to help me with this. I'm building my portfolio website. I'm an illustrator and graphic designer (for printing). My website uses html and css. I introduce a jquery plugin to create a slide show with my work. Until then, everything was working well. The problem appears when I introduce php to my code in order not to repeat the navigation bar all the time. With php and the jquery together I get a blank page in my browser. This link shows the blank page I'm getting using php and jquery together. http://www.raulmv.com/calendar.php This is an example of the site without the jquery. http://www.raulmv.com/graphics.php Could someone please help me with this thanks. 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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="description" content="#" /> <meta name="keywords" content="#" /> <title>#</title> <meta name="google-site-verification" content="1ksaaEb5-Ur8h5ivruWp4iRcUB-tDLyM43L6yCl1OuQ" /> <link href="css/style.css" rel="stylesheet" type="text/css" /> <!-- include jQuery library --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> <!-- include Cycle plugin --> <script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script> <script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="/js/jquery.cycle.all.js"></script> <script type="text/javascript" src="/js/common.js"></script> <!--Google Analytics--> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-12002561-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 class="#" id="portfolio"> <div id="container"> <!--Top Navigation--> <div id="navcontainer"> <?php {include("navbartop.html");} ?> </div> <!--Left Navigation--> <div id="navBar"> <?php include("navbarleft.html"); ?> </div> <!--Info--> <div id="info"> <span class="Title">ANYTIME CALENDAR | 2009</span> <span class="style">Calendar designed to be used any year, any occasion, anytime.</span> </div> <!--Imagenes--> <div id="showreel-nav-wrap"> <span> </span> </div> <ul id="buy-links" class="slideshow"> <li> </li> <li> </li> <li> </li> <li> </li> <li> </li> <li> </li> <li> </li> </ul> <div id="showreel"> <ul class="slideshow pics"> <?xml version="1.0" encoding="utf-8"?> <li><img src="images/Calendar.png" height="522px"/> </li> <li><img src="images/IMG_1162.png" height="522px" /> </li> <li><img src="images/IMG_1307.png" /> </li> <li><a href="images/Calendar/Instructions.gif"><img src="images/Instructions_small.gif" /></a> </li> </ul> </div><!--/showreel--> <script type="text/javascript"> $(function() { var totalImg = $("#showreel li").size() - 1; $("#buy-links li:gt(" + totalImg + ")").remove(); $("#showreel-nav-wrap span").after('<div id="showreel-nav" class="showreel-nav">') $('.slideshow').each(function(index) { $(this).cycle({ fx: 'fade', speed: 'slow', timeout: 0, sync: false, pager: '#showreel-nav', pagerAnchorBuilder: function(i) { if (index == 0) // for first slideshow, return a new anchor return '<a href="#">'+(i+1)+'</a>'; // for 2nd slideshow, select the anchor created previously return '#showreel-nav a:eq('+i+')'; } }); }); //Image to trigger showreel links activeLink = $('#showreel-nav').find('.activeSlide'); nextLink = activeLink.next(); $('.slideshow img').bind('click',function(){ activeLink = $('#showreel-nav').find('.activeSlide'); nextLink = activeLink.next(); nextLink.trigger('click'); }); //Get h1 text length var h1length = $('h1').text().length; if(h1length > 27) { $('.oj-title').css('margin-top','-21px'); } }); </script> <!-- end #mainContent --></div> </body> </html> Those <li> tags Im using is to numbered the images. It might not be a good practice but it works. Thanks for reading this post, I hope someone could help me. It's frustrating I have been for the last two days going around trying to change things and nothing seems to work. hey guys i have the following test html that i want to grab information out of in paticular .match(/\s(\d{1,2}\%)<\/td>/)[1]; now this works for the first % which returns 4% on this line <td style="color: white;"> (4%)</td> but then i have the same matches again Code: CL = temp.match(/\s(\d{1,2}\%)<\/td>/)[1]; alert("CL = " + CL); //returns 4% Neo = temp.match(/\s(\d{1,2}\%)<\/td>/)[2]; alert("Neo = " + Neo);//returns undefined and should return 2% Oak = temp.match(/\s(\d{1,2}\%)<\/td>/)[3]; alert("Oak = " + Oak); //returns undefined and should return 14% Queen = temp.match(/\s(\d{1,2}\%)<\/td>/)[4]; alert("Queen = " + Queen); // returns undefined and should return 27% here is a link to the temp variable because it would get messy here http://pastebin.com/XFyiQ26K I know I can use the functions like parseFromString() to access and modify an existing XML documents, but is it possible to use JavaScript to create a blank xml document? I want to take data entered into the client, package it up as XML and use ajax to transmit it to the server. So far I've written my own class to create a simple xml document, but I'd like to do it properly with the inbuilt functions. Say I have a <textarea> input and I want to strip all the blank lines (lines with only whitespace). I have this regular expression, why doesn't it do anything? I've tried different variations with the flags (m and g). Code: ... var output = input.replace(/^\s*$/gm, "notworking!"); ... The very same regex works fine in my text editor (Notepad2), and I can match all empty lines. Code: LINE1 LINE4 ^(line 3 has some spaces) should become Code: LINE1 LINE4 And when I finally do get this to work, how would I remove the empty line? (previously posted in the wrong forum and re-posted in this one) Hi there, I have scoured the internet looking for the right code but to no avail. I have gotten as far as totaling up my form but now want to format the amounts and total as currency and also want the values that = 0 to just be blank. I have tried to use the code from other solutions (posted on the net) but I just think it is over my head because I cant figure it out. I thought I was close a few times but wasn't able to bring it on home. One of my issues is using somebody's code and not knowing where in my code to place it. http://www.whackyweedremoval.com/wwr-invoice.html I have tried exhaustively to solve on my own but there is a point. Please help My Javascript doesn't display an error when the "bid" field is blank but I want it to. Can someone help me fix it? Everything else works okay but I'm not a Javascript programmer so I don't know where to begin. Code: function checkBid(fieldName,minValue,maxValue){ var numberfield = fieldName; if (chkNumeric(fieldName,minValue,maxValue) == false){ numberfield.select(); numberfield.focus(); return false; } else{ return true; } } function chkNumeric(fieldName,minValue,maxValue){ var checkOK = "0123456789"; var checkStr = fieldName; var allValid = true; var decPoints = 0; var allNum = ""; for (i = 0; i < checkStr.value.length; i++){ ch = checkStr.value.charAt(i); for (j = 0; j < checkOK.length; j++) if (ch == checkOK.charAt(j)) break; if (j == checkOK.length){ allValid = false; break; } if (ch != ",") allNum += ch; } if (!allValid){ alertsay = "The bid field contains one or more invalid characters:\nPlease use only numeric digits in this field ...\n " alert(alertsay); return (false); } var chkVal = allNum; var prsVal = parseInt(allNum); if (chkVal != "" && !(prsVal >= minValue && prsVal <= maxValue)){ alertsay = "Your bid value is outside the acceptable bidding range:\nPlease enter a value from "+minValue+" to "+maxValue+" ...\n " alert(alertsay); return (false); } } Hi everyone, I have a very simple fill-in-the-blank quiz that I would like to add a randomizer to. Right now, the quiz has 3 questions that are asked one at a time, in order. I want to increase this to 100 possible questions (that part I can do), but I want the script to randomly choose 10 of them to ask. Then once the person has taken the quiz, they would be able to try again with 10 new questions. The script is live he http://www.elearnfrenchlanguage.com/...verb-quiz.html I have a quiz with a randomizing script, but it's for multiple choice questions, and I don't know how to adapt it so that it works with my script. Here is the working quiz: http://french.about.com/library/week...frenchquiz.htm And here is the randomizing script: http://french.about.com/library/weekly/longquiz.js I'd be so grateful for any help. Edit: Nevermind
This used to work and suddenly it does not work in IE. Here's the function Code: function pdfWindow(loc) { if(loc == "#RefQuide") { location.href = loc; } else { // The window attributes var window_attribs = "height=650,width=850,resizable=yes,scrollbars=yes"; window.open(loc,"PDF",window_attribs); } } Here's part of the HTML Code: <form name="myForm"> <select name="hypercomList"> <option value="/CWRWeb/pdf/HypercomT4000.pdf">Hypercom T4000 </option> <option value="/CWRWeb/pdf/HypercomT4100.pdf">Hypercom T4100 </option> </select> <input type="button" value="Go!" onclick="pdfWindow(myForm.hypercomList.options[myForm.hypercomList.selectedIndex].value)"> </form> Any ideas why it would open a blank page instead of the PDF? Works ok in FF. I was wondering if someone could help me? In my code below what if answers in question 2 were allowed to be in any order? Like: hips,body,knees or knees,hips,body and so on. How should I modify my code? Anyone please???? Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Quiz</title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <script type="text/javascript"> var answer_list = [ ['False'], ['body,hips,knees'] // Note: No comma after final entry ]; var response = []; function getCheckedValue(radioObj) { if(!radioObj) return ""; var radioLength = radioObj.length; if(radioLength == undefined) if(radioObj.checked) return radioObj.value; else return ""; for(var i = 0; i < radioLength; i++) { if(radioObj[i].checked) { return radioObj[i].value; } } return ""; } function setAnswer(question, answer) { response[question] = answer; } function CheckAnswers() { var correct = 0; var resp, answ; for (var i = 0; i < answer_list.length; i++) { resp = response[i].toString(); resp = resp.toLowerCase(); answ = answer_list[i].toString(); answ = answ.toLowerCase(); //################################################################################################# if (resp == answ) { correct++; if(i==0){ document.forms[0].a1c.style.backgroundImage="url('correct.gif')"; document.forms[0].a1c.value = ""; } else{ document.forms[0].a1d.style.backgroundImage="url('correct.gif')"; document.forms[0].a1d.value = ""; } } else{ if(i==0){ document.forms[0].a1c.style.backgroundImage = "url('incorrect.gif')"; document.forms[0].a1c.value = " ANS: False. Position the head snugly against the top bar of the frame and then bring the foot board to the infant's feet."; } else{ document.forms[0].a1d.style.backgroundImage = "url('incorrect.gif')"; document.forms[0].a1d.value = " ANS: " + answ; } //################################################################################################### } } document.writeln("You got " + correct + " of " + answer_list.length + " questions correct!"); } </script> </head> <body> <form action="" method="post"> <div> <b>1. When measuring height/length of a child who cannot securely stand, place the infant such that his or her feet are flat against the foot board.</b><br /> <label><input type="radio" name="question0" value="True" />True</label> <label><input type="radio" name="question0" value="False" />False</label> <br /> <textarea rows="2" cols="85" name="a1c" style="background-repeat:no-repeat"></textarea> <br /> <b>2. When taking a supine length measurement, straighten the infant's <input type="text" name="question1_a" size="10" />, <input type="text" name="question1_b" size="10" />, and <input type="text" name="question1_c" size="10" />.</b> <br /> <textarea rows="2" cols="85" name="a1d" style="background-repeat:no-repeat"></textarea> <br /> <input type="button" name="check" value="Check Answers" onclick="setAnswer(0,getCheckedValue(document.forms[0].question0));setAnswer(1,[document.forms[0].question1_a.value,document.forms[0].question1_b.value,document.forms[0].question1_c.value]);CheckAnswers();" /> </div> </form> </body> </html> I have a popup window that has a "link" inside it, which needs to have a target=_blank but when ever clicked in IE, it stays inside the same window. I tried all of the following, none work PHP Code: <a href='http://www.myurl.net' onclick='window.close();' target='_blank'> <a href="http://www.myurl.net" target="_blank" onClick="javascript:window.close()"> <a href="http://www.myurl.net" target="_blank" onClick="javascript: setTimeout(window.close, 10);"> Thanks Sonny Hi everyone, I run a math site and I just recently built a little program to generate math problems. When the user submits the correct answer the program changes the problem and all the steps/hints. Everything works fine except that during the change over there are all these weird blocks (same color as my background) (*FireFox Only). It only lasts for a couple of seconds, but it would be nicer if it smoothly replaced the problem. Here is the test site: http://www.rootmath.org/test/solving-limits The program/practice problem is at the bottom, if you don't know how to solve it you can hit "hint" until it gives you the answer. When you enter the correct answer and then click for a new problem you'll see the funky blocks. Any help/suggestions would be greatly appreciated! Here is the code: writeProblem() is called when the user gets the right answer and asks for another problem: Code: var writeProblem = function(){ //these are neccessary after the first call to writeProblem. $(".steps").hide(); $("#submit_answer").show(); $("#next_problem").hide(); showStep.reset(); //CLEAR "steps_area" var problem_area = document.getElementById('steps_area'); while(problem_area.firstChild){ problem_area.removeChild(problem_area.firstChild); } //Create a limit problem var limit = limits(); limit.setDenominator(rand(6,0)); var denom = limit.getDenominator(); var randInt = 0//rand(3,0); var lim = limit.getType(randInt, denom); var step = lim.step(denom); answer = lim.getAnswer(); //made global so checkAnswer() can access it var x = document.getElementById('problem'); x.innerHTML = addLatex(lim.problem); var problem_area = document.getElementById('steps_area'); //loop over array of steps and print them to steps div var length = step.length; for(var i=0; i<length; i++){ var divTag = document.createElement("div"); divTag.id = "step" + i; divTag.className = "steps"; divTag.innerHTML = step[i]; problem_area.appendChild(divTag); MathJax.Hub.Queue(["Typeset",MathJax.Hub,'step' + i]); } // MathJax Queue for processing latex that javascript filled in MathJax.Hub.Queue(["Typeset",MathJax.Hub,'problem']); } hi, When I navigate to a page with Ajax on my iphone or ipad, it doesn't show up, page is just blank, I have checked for errors and there is no errors?! here is my Ajax code Code: function datecheckFunction(){ var datecheckRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari datecheckRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ datecheckRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ datecheckRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server datecheckRequest.onreadystatechange = function(){ if(datecheckRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxDiv'); ajaxDisplay.innerHTML = datecheckRequest.responseText; } } var datepicker = document.getElementById('datepicker').value; var queryString = "?datepicker=" + datepicker; //Add the following line datecheckRequest.open("GET", "http://www.affordableappliancerepairs.co.uk/admin/checkdate.php" + queryString, true); datecheckRequest.send(null); } I have an ajax dependent drop down set up for location fields and am having trouble figuring out how to clear the dependent selects if the parent select is changed to blank. I set up a function to clearFields: Code: <script> function clearFields() { document.getElementById('cb_state').value = ""; } </script> And then set the parent to clearFields onchange: Code: onchange='ajaxFunction();clearFields();' This doesn't clear the field, but even if it did it would clear the field on change regardless of what's selected, what I need is for the function to fire only if the blank option is selected. How do I need to go about this? |