JavaScript - Checking The Text In A Textbox Against A Javascript Array
Hello,
Can you someone point me to the right script? I have a text box and would like to see if the value of the input matches the values defined in a JavaScript array. For example, the JavaScript array will hold five values: v1 = Tom v2 = Jerry v3 = Michael v4 = Stephanie v5 = Michelle If the text box does not equal one of those values, an alert will pop up stating it does not match. Thanks. Similar TutorialsI am working on a page where the user will select a location from a dynamically generated dropdown list. I was able to create the php multidimensional array (tested and working) from a MySql database using the users information at login, but I'm having problems converting it to a javascript multidimensional array. I need to be able to access variables that I can pass to a number of text fields within an html form. For instance, if a user belongs to a company with multiple addresses, I need to be able to let them select the address they need to prepopulate specific text fields. php array creation: Code: if ($row_locations) { while ($row_locations = mysql_fetch_assoc($locations)) { $mail[$row_locations['comp_id']]=array('mailto'=>$row_locations['mailto'], 'madd'=>$row_locations['madd'], 'madd2'=>$row_locations['madd2'], 'mcity'=>$row_locations['mcity'], 'mstate'=>$row_locations['mstate'], 'mzip'=>$row_locations['mzip'], 'billto'=>$row_locations['billto'], 'badd'=>$row_locations['badd'], 'badd2'=>$row_locations['badd2'], 'bcity'=>$row_locations['bcity'], 'bstate'=>$row_locations['bstate'], 'bzip'=>$row_locations['bzip']); } } javascript function - this should create the array and send variables to text fields. Code: function updateAddress() { var mail = $.parseJSON(<?php print json_encode(json_encode($mail)); ?>); { if (comp_id in mail) { document.getElementById('mailto').value=mail.comp_id.mailto.value; document.getElementById('madd').value=mail.comp_id.madd.value; document.getElementById('madd2').value=mail.comp_id.madd2.value; document.getElementById('mcity').value=mail.comp_id.mcity.value; document.getElementById('mstate').value=mail.comp_id.mstate.value; document.getElementById('mzip').value=mail.comp_id.mzip.value; } else { document.getElementById('mailto').value=''; document.getElementById('madd').value=''; document.getElementById('madd2').value=''; document.getElementById('mcity').value=''; document.getElementById('mstate').value=''; document.getElementById('mzip').value=''; } } } Where is this breaking? Thanks in advance. Hello. I've been teaching myself HTML and CSS for a while, and now I've moved into the world of Javascript (but I'm still very much a beginner). For practice, I've been building a sample sign up form for a mock website, and I'm having problems with the birthdate section. The idea I had was to have MM, DD, and YYYY be the default values of my 3 textboxes (as an example for users), then set the value to nothing when the box gained focus. That all works fine, but I ran into problems when I tried to write an if statement to set the value back to MM, DD, or YYYY if the value was still nothing when the user clicked away. As it is now it just replaces the text inputted into the textbox (which of course is not good). Any ideas for what the problem might be? Code: <form name="signup" action="javascript:void(0);" method="post"> <table> <tr> <td>Date Of Birth:</td> <td> <input name="DOBmonth" type="text" value="MM" size="2" style="color: #555555;" onFocus="clearDOBmonth()" onBlur="restoreDOBmonth()" /> <input name="DOBday" type="text" value="DD" size="2" style="color: #555555;" onFocus="clearDOBday()" /> <input name="DOByear" type="text" value="YYYY" size="4" style="color: #555555;" onFocus="clearDOByear()" /></td> </tr> <tr> <td></td> <td><button name="Submit" type="submit" style="font-size: 1em;">Sign Up</button></td> </tr> </table> </form> <script type="text/javascript" language="javascript"> <!-- document.signup.DOBmonth.value="MM"; document.signup.DOBday.value="DD"; document.signup.DOByear.value="YYYY"; function clearDOBmonth() { document.signup.DOBmonth.value="";} function clearDOBday() { document.signup.DOBday.value="";} function clearDOByear() { document.signup.DOByear.value="";} function restoreDOBmonth() { if ('document.signup.DOBmonth.value = ""') { document.signup.DOBmonth.value = "MM"; // alert(document.signup.DOBmonth.value); } } //--> </script> Another side question, if I set a variable equal to the value of a textbox, then change the value of the variable, does that also change the value of the textbox? or is the variable no longer associated with the textbox. Example: Code: var a = document.form.textbox.value; a = blue; does document.form.textbox.value = blue? or is var a now completely independent of the textbox value? Thanks! Hi, I know this is painfully obvious, but I can't get my head around it. Basically, these loops: Code: for (var p=0; p < routeInfo.length; p++) { times = routeInfo[p].getElementsByTagName("time"); dirs = routeInfo[p].getElementsByTagName("dirs"); dist = routeInfo[p].getElementsByTagName("dist"); for (q=0;q<dirs.length;q++) { count++; time = GXml.value(routeInfo[p].getElementsByTagName("time")[q]); dir = GXml.value(routeInfo[p].getElementsByTagName("dirs")[q]); dist = GXml.value(routeInfo[p].getElementsByTagName("dist")[q]); if (time.length>1) { way+='<div class="dir">'+count+'. '+dir+'</div>'+'<div class="results"><div class="time">'+time+'</div><div class="dist">'+dist+'</div><br><br>'; } else way+='<div class="dir">'+count+'. '+dir+'</div><br>'; } } outputs lines of text, with two <br> between them. What I want is for if it's the last loop for that only to be one <br> so I'm thinking something like this: Code: if (last loop) {end =<br>} else end=<br><br> ... way+='<div class="dir">'+count+'. '+dir+'</div>'+'<div class="results"><div class="time">'+time+'</div><div class="dist">'+dist+'</div>'+end; but I can't figure out what that "last loop" code should be. Any ideas? Hey guys. I need a little help with checking elements in my array. I created an array of size 50 and initialized all elements to 1. What i want to do is if the user types in the number "1" into the prompt box, i want it to check the first 15 elements and increase only one of the elements by 1, and if the element has already been increased by 1 then i want it to check the next element and see if its been increased, if the element has been increased then it needs to move on to the next one and check that. If the element is 1, then it can be increased by "1", if the element is 2 then i need it to check the next element. If all elements within the first 15 have increased by 1, it should just alert the user that all slots have been assigned. Is there a way to do this? Thanks for your time
I am using the following script on an e-commerce site to ensure that not both drop downs cannot be selected at the same time, as well as ensuring one must be selected at all times. Code: <script language="javascript"><!-- function validate(cart_quantity) { if (((cart_quantity.elements['id[2]'].value == 9999) && (cart_quantity.elements['id[3]'].value == 9999)) || ((cart_quantity.elements['id[2]'].value != 9999) && (cart_quantity.elements['id[3]'].value != 9999))) { alert('Please select only one option!'); cart_quantity.elements['id[2]'].value = 9999; cart_quantity.elements['id[3]'].value = 9999; cart_quantity.elements['id[2]'].focus(); return false; } } //--></script> The initial value of the drop down is set to 9999 off the bat. The problem with this code is that not all of my product pages have these 2 drop downs so I wanted to try and add in an if statement saying that if id2=9999 and id3 == null then pop up the error. That didnt work because I don't think it can be equal to null if it does not exist on the page. So instead I tried to do the following: Code: <script language="javascript"><!-- function validate(cart_quantity) { cart_quantity.elements['id[3]'] = 99999; if (((cart_quantity.elements['id[2]'].value == 9999) && (cart_quantity.elements['id[3]'].value == 9999)) || ((cart_quantity.elements['id[2]'].value != 9999) && (cart_quantity.elements['id[3]'].value != 9999))) { alert('Please select only one option!'); cart_quantity.elements['id[2]'].value = 9999; cart_quantity.elements['id[3]'].value = 9999; cart_quantity.elements['id[2]'].focus(); return false; } if (((cart_quantity.elements['id[2]'].value == 9999) && (cart_quantity.elements['id[3]'].value == 99999))) alert('Please select an option!'); cart_quantity.elements['id[2]'].value = 9999; return false; } //--></script> I tried to assign id3 a value of 99999 so that on pages that it doesnt get reassigned after (i.e pages it does not exist on) it will still be equal to 99999 and pop up the error according to the second if clause. Unfortunately that did not work either. Is there any other way I can do via javascript? I'm having major pains trying to figure this out. I'm kind of new to Javascript, I need to open a text file from an external server, store each line in an array, then search that array for a certain word (HIGH), and if it exists then write something to the webpage, and if not, write something else. Here is what I have so far: Code: <html> <head> <title>Test</title> <script> <!-- function test(x) { if (wxd1txt.readyState === 4 && wxd1txt.status === 200) { // Makes sure the document is ready to parse and Makes sure it's found the file. var wxd1text = wxd1txt.responseText; var wxd1array = wxd1txt.responseText.split("\n"); // Will separate each line into an array var wxd1high = wxd1array.toString(); //Converting the String content to String //var highsearchreg = new RegExp("HIGH"); //var wxd1high = wxd1array[x].search(highsearchreg); document.write(wxd1high); if (wxd1high.search("HIGH") >= 0){ document.write("HIGH RISK");} else { document.write("NO RISK");} } } //--> </script> </head> <body> Hi! <script> <!-- var Today = new Date(); var ThisDay = Today.getDate(); var ThisMonth = Today.getMonth()+1; var ThisYear = Today.getYear(); var Hour = Today.getHours(); var Day2 = Today.getDate()+1; var Day3 = Today.getDate()+2; if (navigator.appName != "Microsoft Internet Explorer") { ThisYear = ThisYear + 1900;} if (ThisMonth < 10) { ThisMonth = "0" + ThisMonth;} if (ThisDay < 10) { ThisDay = "0" + ThisDay;} if (Hour == 2 || Hour == 22 || Hour == 23 || Hour == 0 || Hour == 1) { var wxHourd1 = 0600} else if (Hour >= 3 && Hour <= 10) { var wxHourd1 = 1300;} else if (Hour >= 11 && Hour <= 13) { var wxHourd1 = 1630;} else if (Hour >= 14 && Hour <= 16) { var wxHourd1 = 2000;} else if (Hour >= 17 && Hour <= 21) { var wxHourd1 = 0100;} //var wxurld1 = "http://www.spc.noaa.gov/products/outlook/archive/"+ThisYear+"/KWNSPTSDY1_"+ThisYear+""+ThisMonth+""+ThisDay+""+wxHourd1+".txt"; var wxurld1 = "http://www.spc.noaa.gov/products/outlook/archive/2010/KWNSPTSDY1_201005101300.txt" //(High risk day for testing) //document.write(wxurld1); //Use this to verify this section is working if (window.XMLHttpRequest) { wxd1txt=new XMLHttpRequest(); } else // IE 5/6 { wxd1txt=new ActiveXObject("Microsoft.XMLHTTP"); } wxd1txt.open("GET", wxurld1, true); wxd1txt.onreadystatechange = test(); // --> </script> </body> </html> When added to a webpage, nothing shows up except the "Hi!" and there are no errors in the Javascript Console in Google Chrome. Is this possible with Javascript, and if so, what am I doing wrong or not doing? Also, I have 2 URLs, one is a text file that has the HIGH text I want for an example, the other is the current file, which shouldn't have HIGH in it (unless the weather in the US turns really bad) I have a Java Script that displays a Daily Affirmation on a webpage from an array of 365 Affirmations within the same html webpage file. This makes the html file size way too large. So I would like for the java script to read the array from an external text file on the same website server. Please provide me the Code to insert within my script which will read the array from an external text file - and also the format that the array of 365 lines must be typed into the external text file. I am not a Javascript Programmer - and know nothing about Javascript, so please write your reply at my (lack of) knowledge Level. Thank you in advance! Here is the code I am using. <script language=javascript> <!-- Date.prototype.getDOY = function() {var onejan = new Date(this.getFullYear(),0,1); return Math.ceil((this - onejan) / 86400000);} var today = new Date(); var DOY = today.getDOY(); var HL=new Array() //Configure the following array to hold the 365 HLs for each day of the year HL[1]='HL 1 goes here' HL[2]='HL 2 goes here' HL[3]='HL 3 goes here' // Jump to Day 224 of the year for this example only HL[224]='I am surrounding myself with positive and supportive people. When I nurture relationships that give me energy and enjoyment, I mirror my beliefs that I deserve such gifts.' HL[225]='Today I affirm my own worth and value, and discover that the world agrees with me.' HL[226]='I am sowing seeds based on a healthy belief in my own self-worth. My life is flourishing with growing love, contentment, and exciting possibilities.' HL[227]='HL 227 goes here' HL[228]='HL 228 goes here' // Jump to last HL for Day 365 of year - for this example only HL[365]='HL 365 goes here' document.write(HL[DOY]) //--> </script> how would you make a function that cheks if any text is in a text box.
I'm taking a beginning javascript class and have been trying to figure out one last part of a homework assignment and am just not seeing how to work it out. Any help is greatly appreciated! What I'm having trouble with is doing the text verification. When a user selects an option from the select list they then need to type in the text area given. If the user doesn't type the word selected in the list then an error message should appear under the text area. If you look at my code you'll see that I have the text_check() function doing the verification. I can get it to work when there is only one option but once I add the other two it stops working. I've tried if... else and other variations, but can't seem to nail it down. Thanks! Code: function select_function() { var medical=document.getElementById("medical_list") var selected_item=medical.selectedIndex if (selected_item==0) { document.getElementById("enter_info").innerHTML="Enter Your" +"<span style='color:blue'>" +" Medication" + "</span>"+ " Information" var comments=document.getElementById("comments"); comments.focus(); } if (selected_item==1) { document.getElementById("enter_info").innerHTML="Enter Your" +"<span style='color:blue'>" +" Hospitalization" + "</span>"+ " Information" var comments=document.getElementById("comments"); comments.focus(); } if (selected_item==2) { document.getElementById("enter_info").innerHTML="Enter Your" +"<span style='color:blue'>" +" Physician" + "</span>"+ " Information" var comments=document.getElementById("comments"); comments.focus(); } } function text_check() { var user_comments=document.getElementById("comments").value.toLowerCase(); var med_comment=user_comments.indexOf('medication'); var hosp_comment=user_comments.indexOf('hospitalization'); var phys_comment=user_comments.indexOf('physician'); mySelectList = document.getElementById("medical_list"); if (mySelectList.value='Medication' && med_comment==-1) { document.getElementById("word_error").innerHTML="You need to have the word,"+"<span style='color:red'>"+" Medication"+"</span>"+" somewhere in the text"; } if (mySelectList.value='Hospitalization' && hosp_comment==-1) { document.getElementById("word_error").innerHTML="You need to have the word,"+"<span style='color:red'>"+" Hospitalization"+"</span>"+" somewhere in the text"; } if (mySelectList.value= 'Physician' && phys_comment==-1) { document.getElementById("word_error").innerHTML="You need to have the word,"+"<span style='color:red'>"+" Physician"+"</span>"+" somewhere in the text"; } } function submit_alert() { alert("You submitted the form") } function clear_error() { document.getElementById("word_error").innerHTML=""; } function changeDR() { var my_textarea=document.getElementById("comments"); var comment_string=my_textarea.value; var doctor=comment_string.indexOf('Dr.'); var comment_string2=''; if (comment_string < 0) { comment_string2=comment_string } else { comment_string2=comment_string.replace('Dr.','Doctor') } my_textarea.value=comment_string2; } </script> </head> <body style="background-color: silver"> <h2>Medical History</h2> Select Category: <br> <select id="medical_list" onChange="select_function();"> <option>Medication</option> <option>Hospitalization</option> <option>Physician</option> </select> <br><br><br> <div id="enter_info">Enter Your <font color="blue">Medication</font> Information:</div> <br> <form method="post" action=""> <textarea id="comments" cols="60" rows="15" onBlur="text_check();" onFocus="clear_error();" onkeyup="changeDR();"> </textarea><br> <div id="word_error"></div><br> <input type="submit" value="Submit Information" onClick="submit_alert();"/> </form> </body> </html> 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 am looking to have the user input a word into a textbox then when the user hits an "Add" button, the word is stored to an array and then is displayed in a table. I also want the textbox to clear after the "Add" button is pressed. Next, I want the user to be able to input another word into the textbox and when the "Add" button is pressed, have that word stored to same array as the first word but just to a different number. e.g. ingredient(0)=first word; ingredient(1)=second word. Then I want the second word to be displayed right below the first word in the table, in the next line down.This is what I have so far. You can also see at http://www.stuffedpantry.com/startsearch.html <code> <html> <head> <title>Stuffed Pantry~Recipe Search (Under Construction)</title> <link rel="stylesheet" type="text/css" href="main.css"> </head> <body> <script type="text/javascript"> var ingredients=new Array(); </script> <div id="lftBar"> </div> <div id="level0"> <div id="level1"> <div id="level3"> <div id="rgtBar"> <script type="text/javascript"><!-- google_ad_client = "pub-1493036398028662"; /* 160x600, created 3/15/10 */ google_ad_slot = "0764917859"; google_ad_width = 160; google_ad_height = 600; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div> <div id="topBar"> <img class="displayed" src="logo.jpg"> <div id="advBar"> <p align="center"><font font size="6" color="darkblue"><b><i>A recipe search engine.</i></b></font></p> </div> </div> <div id="level2"> <div id="main"> <p align="center"><font font size="4">Welcome to the search engine of stuffedpantry.com! This page is designed to to help you search our database of recipes to find the perfect recipe for you! So to begin, type in an ingredient. Any ingredient will work! You could put in a type of seasoning, like paprika. Or you can put in a type of soup, like chicken noodle soup! Anything that is considered food will work! And if there isn't a recipe containing the ingredient(s) you have chosen, then submit one to us! You can submit one <a href="recipesubmit.html">here!</font></a> <div id="level4"> <form > <table border="0" cellpadding="0" cellspacing="0" align="center"> <tr><td align="center"><label for="ingredient"><b>Enter Ingredient: </b></label><input type="text" name="ingredient" id="textbox1" style="width:200px;"><div style="clear:left;height:20px;"></div></td><td> <tr><td align="center"><input type="button" value=" Add " onclick="getElementById('ing').innerHTML = getElementById('textbox1').value"></td></tr> <tr><td> </td></tr> <tr><td id="ing"</td></tr> <tr><td> </td></tr> <tr><td align="center"><input type="radio" name="choose" value="only" checked>Search recipes that have <b>ONLY</b> these ingredients<br/><input type="radio" name="choose" value="including">Search recipes that <b>INCLUDE</b> these ingredients</td></tr> <tr><td> </td></tr> <tr><td align="center"><input id="button1" type="submit" value=" Search! "</td></tr> </form> </div> </div> </div> </div> </div> </div> </body> </html> </code> Basically what I am looking for is a script that when you click a button, it changes the text in a text box to asterisks, AND also submits the information to the server, so it can be saved. Even if it does not send info to the server, if it can switch it, That would be good too. Can anyone help me with this script? I am sure that lots of people have seen the Credit Card commercial on T.V. with Emmitt Smith and him putting in his password of "Catch-22" then clicking on a button, and the password automatically changes to asterisks (********) in the textbox. How is this done? Is it js, ssl or what? If it is a ssl, can someone tell me what kind it would be? I would like to have something like that for a website of mine, where the user can create his password, and see it before he/she confirms it as the password by clicking on the "confirm" button. I dont like having to enter my password twice to verify it, so I think that this would do the job better for me. Thanks, ImperialSpider I use the following code to create a hidden iFrame on a page, dynamically Code: var i = document.createElement('iframe'); i.style.display = 'none'; i.onload = function() { i.parentNode.removeChild(i);}; i.src = 'http://www.mysite.com'; document.body.appendChild(i); i.id='frame1'; Now, document.getElementById('frame1').contentDocument.getElementById('text01').value Should have given me the value in 'text01', but it doesn't. It doesn't work even inside the iFrame's onload event. ('text01' is a textbox which is on the page inside the iFrame - its name and id are both 'text01') Is there any other method to get the text in a textbox within an iFrame? Please help me to correct the code. Thanks in advance. Hi all. This is a generic question as Google didn't help at all, does anyone know how to check if javascript is enabled and then I want to display info based on that. I don't mind how I do it, HTML, PHP or whatever Regards, Magnetica Hi. I'm having some trouble with validating all my fields in my form. I'm posting my code here. Code: function validateForm() {var chk = document.forms["EntryPage"]["studentname"].value; if (chk==null || chksdtnm=="") { alert("Student name must be filled out"); return false; } if (chk==null || chksdtnm=="") { alert("Student ID must be filled out"); return false; } } I need to alert the user with a messagebox for six fields if ever they're not filled in. How do I achieve that? Hey Guys, I am a student doing my Cert IV in IT and am having a bit of trouble with some code. I have a form that when a letter is entered it returns a message saying you need to enter numbers in, and am trying to find a way of it checking if there are spaces in the numbers entered at the same time as checking if a number has been entered. My code looks as follows: Code: <html> <head> <title>Activity 2.25</title> </head> <script type="text/javascript"> function validateform() { var element; var BikeMoney; var TVMoney; var iPodMoney; var CarPrice; var flag; flag="OK" element=document.getElementsByTagName('input'); for(counter=0; counter<element.length; counter++) { switch (element[counter].type) { case "submit": break; default: if(isNaN(element[counter].value)) { alert("You will need to enter a number into " + element[counter].name); flag="NotOK" } else { BikeMoney=element[0].value; TVMoney=element[1].value; iPodMoney=element[2].value; CarPrice=element[3].value; } } } if(flag=="OK") if ((Number(BikeMoney)) && (Number(TVMoney)) && (Number(iPodMoney)) && (Number(CarPrice))) { TotalMoney = parseFloat (BikeMoney) + parseFloat (TVMoney) + parseFloat (iPodMoney) if(TotalMoney >= CarPrice) { alert("The total money is " + TotalMoney + " and the car price is " + CarPrice + " and you can afford the car"); } else { alert("The total money is " + TotalMoney + " and the car price is " + CarPrice + " and you cannot afford the car"); } } else { alert("Enter numbers Please"); } } </script> <body> <form name="input form" method="post" action=""> <table> <tr><td>Enter money from bike sale</td><td><input type="text" name="Bike Money"></td></tr> <tr><td>Enter money from TV sale</td><td><input type="text" name="TV Money"></td></tr> <tr><td>Enter money from iPod sale</td><td><input type="text" name="iPod Money"></td></tr> <tr><td>Enter the price of the car</td><td><input type="text" name="Car Price"></td></tr> <tr><td></td><td><input type="submit" value="Submit Details" onclick=validateform()></td></tr> </table> </form> </body> </html> Hai Forum, May be this question is not in correct format, I want to know about how to check a particular file is exists or not ? using Javascript.One thing without using ActiveXObject because it is supports in IE only. Thanking You, Santosh Srinivas.G I have a javascript that should convert any date into a number between 1 and 260. Based on the outcome of that calculation, a viewer is directed to a specific web page. How can I verify the calculation? How can I see what number javascript is arriving at so I can backtrack to the error? It is not serving up the correct page. I have compared the results to a calculator on another website that uses a different script to calculate the same result -- that's why I am saying the end results are not correct. On the other website, scroll down to where you enter a date. It returns a name just above the date (example: July 25, 1970 returns Electric Star). The script I included above returns Yellow Sun. July 25, 1970 should = 68. Code: function calculate() { if(!isValidDate()) return; var result = 0; var cuttingAge = 260; var yearBox = document.getElementById("year"); var year = yearBox.value; var month = document.getElementById("month").value; var day = document.getElementById("day").value; //Rule # 1 if(month==1 || month==2){ var selectedYearIndex; for(var i=0; i<yearBox.options.length; i++){ if(yearBox.options[i].selected){ selectedYearIndex = i; break; } } year = yearBox.options[selectedYearIndex-1].value; } //Rule # 2 var monthLength = new Array(); monthLength[0]=0; monthLength[1]=31; monthLength[2]=29; monthLength[3]=31; monthLength[4]=30; monthLength[5]=31; monthLength[6]=30; monthLength[7]=31; monthLength[8]=31; monthLength[9]=30; monthLength[10]=31; monthLength[11]=30; monthLength[12]=31; monthLength[13]=31; monthLength[14]=29; var dayPassed = 0; var tempMonth = month; if(month<3) //If its january or february tempMonth = parseInt(tempMonth) +12; //Add previous year's days for(var i=3; i<tempMonth; i++){ dayPassed += monthLength[i]; } dayPassed += parseInt(day) -1; dayPassed = dayPassed%cuttingAge; //Rule # 3 result = parseInt(year) + parseInt(dayPassed); //Rule # 4 if(result > cuttingAge) result -= cuttingAge; //Rule # 5 var pendant = new Array(); var abc = new Array(); pendant[0] = { name:"imix", values:new Array(1, 21, 41, 61, 81, 101, 121, 141, 161, 181, 201, 221, 241) }; pendant[1] = { name:"ik", values:new Array(2, 22, 42, 62, 82, 102, 122, 142, 162, 182, 202, 222, 242) }; pendant[2] = { name:"akbal", values:new Array(3, 23, 43, 63, 83, 103, 123, 143, 163, 183, 203, 223, 243) }; pendant[3] = { name:"kan", values:new Array(4, 24, 44, 64, 84, 104, 124, 144, 164, 184, 204, 224, 244) }; pendant[4] = { name:"chicchan", values:new Array(5, 25, 45, 65, 85, 105, 125, 145, 165, 185, 205, 225, 245) }; pendant[5] = { name:"cimi", values:new Array(6, 26, 46, 66, 86, 106, 126, 146, 166, 186, 206, 226, 246) }; pendant[6] = { name:"manik", values:new Array(7, 27, 47, 67, 87, 107, 127, 147, 167, 187, 207, 227, 247) }; pendant[7] = { name:"lamat", values:new Array(8, 28, 48, 68, 88, 108, 128, 148, 168, 188, 208, 228, 248) }; pendant[8] = { name:"muluk", values:new Array(9, 29, 49, 69, 89, 109, 129, 149, 169, 189, 209, 229, 249) }; pendant[9] = { name:"oc", values:new Array(10, 30, 50, 70, 90, 110, 130, 150, 170, 190, 210, 230, 250) }; pendant[10] = { name:"chuen", values:new Array(11, 31, 51, 71, 91, 111, 131, 151, 171, 191, 211, 231, 251) }; pendant[11] = { name:"eb", values:new Array(12, 32, 52, 72, 92, 112, 132, 152, 172, 192, 212, 232, 252) }; pendant[12] = { name:"ben", values:new Array(13, 33, 53, 73, 93, 113, 133, 153, 173, 193, 213, 233, 253) }; pendant[13] = { name:"ix", values:new Array(14, 34, 54, 74, 94, 114, 134, 154, 174, 194, 214, 234, 254) }; pendant[14] = { name:"men", values:new Array(15, 35, 55, 75, 95, 115, 135, 155, 175, 195, 215, 235, 255) }; pendant[15] = { name:"cib", values:new Array(16, 36, 56, 76, 96, 116, 136, 156, 176, 196, 216, 236, 256) }; pendant[16] = { name:"caban", values:new Array(17, 37, 57, 77, 97, 117, 137, 157, 177, 197, 217, 237, 257) }; pendant[17] = { name:"etznab", values:new Array(18, 38, 58, 78, 98, 118, 138, 158, 178, 198, 218, 238, 258) }; pendant[18] = { name:"cauac", values:new Array(19, 39, 59, 79, 99, 119, 139, 159, 179, 199, 219, 239, 259) }; pendant[19] = { name:"ahau", values:new Array(20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260) }; var redirecctPages = new Array(); redirecctPages["chuen"] = "http://store.mayankin.com/blue-monkey/"; redirecctPages["eb"] = "http://store.mayankin.com/yellow-human/"; redirecctPages["ben"] = "http://store.mayankin.com/red-skywalker/"; redirecctPages["ix"] = "http://store.mayankin.com/white-wizard/"; redirecctPages["men"] = "http://store.mayankin.com/blue-eagle/"; redirecctPages["cib"] = "http://store.mayankin.com/yellow-warrior/"; redirecctPages["caban"] = "http://store.mayankin.com/red-earth/"; redirecctPages["etznab"] = "http://store.mayankin.com/white-mirror/"; redirecctPages["cauac"] = "http://store.mayankin.com/blue-storm/"; redirecctPages["ahau"] = "http://store.mayankin.com/yellow-sun/"; redirecctPages["imix"] = "http://store.mayankin.com/red-dragon/"; redirecctPages["ik"] = "http://store.mayankin.com/white-wind/"; redirecctPages["akbal"] = "http://store.mayankin.com/blue-night/"; redirecctPages["kan"] = "http://store.mayankin.com/yellow-seed/"; redirecctPages["chicchan"] = "http://store.mayankin.com/red-serpent/"; redirecctPages["cimi"] = "http://store.mayankin.com/white-world-bridger/"; redirecctPages["manik"] = "http://store.mayankin.com/blue-hand/"; redirecctPages["lamat"] = "http://store.mayankin.com/yellow-star/"; redirecctPages["muluk"] = "http://store.mayankin.com/red-moon/"; redirecctPages["oc"] = "http://store.mayankin.com/white-dog/"; var pendantName; for(var i =0; i<pendant.length; i++){ var found = false; for(var j=0; j<pendant[i].values.length; j++){ if(result == pendant[i].values[j]){ pendantName = pendant[i].name; found = true; break; } } if(found) break; } document.location = redirecctPages[pendantName]; } /** * Comment */ function isValidDate() { var year = document.getElementById("year").value; var month = document.getElementById("month").value; var day = document.getElementById("day").value; if(month==2 && day>29){ alert("Please select a valid date"); return false } if((month==4 || month==6 || month==9 || month==11) && day>30){ alert("Please select a valid date"); return false } return true; } I was just wondering how I could change a html text input tpe from text to password on the on click and when the user clicks off it will change back to text just like facebook does.
I have an asp.net textbox. I need to use javascript so that there are no postbacks. I would like to click the button and the textbox height kept increases each time the user clicks the button. So far I can toggle: function resize(){ var textbox = $get('<%=txtWhoTo.ClientID %>'); textbox.style.height = textbox.style.height == '56px' ? '23px' : '56px'; } I would like to increase the height 56px each time the clicks the button. |