JavaScript - Js Array Output Recognition
Hi,
I have 3 functions. I do not know how to have 2 functions recognize the output of an array from the other function. All of this revolves around input(text boxes). What is the array's output? In other words, how do I get the newly added textboxes recognized by the initial functions - what are they called? I have tried adding names like "No. of Hours[1]"; "No. of Hours(1)"; or,"No. of Hours1"; but none of that works. For example, one of the inputs is called "No. of Hours". That is the input textbox on the web page. When the add new rows array is invoked it adds new input textboxes and the new element is Code: el.type = 'text'; el.name = 'No. of Hours' + iteration; el.id = 'No. of Hours' + iteration; el.size = 7; cellRight.appendChild(el); What is this new input/element called so that I can refer to it for the coded function shown below? The first function provides validation for user input. Code: function checkQuarters( fld ) { var val = parseFloat(fld.value); if ( isNaN(val) || ( val*4 != Math.floor(val*4) ) ) { alert("Value must be a numeric and a multiple of 0.25"); return false; } return true; } </script> The input for the above function is Code: <td> <form style="width: 5px; height: 1px;"> <input type="text" name="No. of Hours" id="No. of Hours" style="width: 70px;" onblur="checkQuarters(this);" /> </form></td> The array outputs added textboxes thusly, Code: new_rows[row_count]['cell3']=sel; var cellRight = row.insertCell(3); var el = document.createElement('input'); el.type = 'text'; el.name = 'No. of Hours' + iteration; el.id = 'No. of Hours' + iteration; el.size = 7; cellRight.appendChild(el); new_rows[row_count]['cell']=el; row_count++; The other function uses a JQuery for a datepicker. Code: <script type="text/javascript"> $(function() { $("#startdate").datepicker(); $("#enddate").datepicker(); }); </script> The input is this. Code: <td><input style="width: 70px" type="text" id="startdate"></td> <td><input style="width: 70px" type="text" id="enddate"></td> I am lost on this and could really use some help and guidance. Thanks, John Similar TutorialsHey guys, if someone could help point me in the right direction that would be great. I cant get seem to get this array to print the numbers 1 to 15 out. When I preview I get nothing, anyone know what I am doing wrong? Thanks to those that reply. thanks got it I was wondering if there was any way to determine what browser the remote address is using through JavaScript preferably or any other language and if so how to direct them to another page if they're using a specific browser...
Hi How can i output two maximum numbers of an array if they are equal? var flower["roses", "violets", "buttercups", "daisies"]; var flowerAmounts[9, 8, 3, 9]; Output should be: The maximum amount of flowers is 9. There are 9 roses and 9 daisies. Hope someone can help, thanks I have an array, I can not figure out how to take myTemplateholder = myTemplateholder.replace(" "+children[child],children[child]+"<div id='questionRadio'><input type='radio' name='answer' value='Y' /> Y <input type='radio' name='answer' value='N' /> N <input type='radio' name='answer' value='NA' /> N/A<br /></div>");} to display to separate lines. Right now, if there is more than one value, it gets added together. Here's the rest of the code: Code: function showText(){ // var myTemplateholder = document.getElementById('myTemplateholder').innerHTML; // document.getElementById('showMe').innerHTML = myTemplateholder; var children = new Array('Chills','Fatigue','Fever','Health History','Screening','Eye-ROS','Skin','Assessment','General Appearance','Vitals','Hearing','200','300','400','500'); var myTemplateholder = $('#myTemplateholder').text(); myTemplateholder = myTemplateholder.replace("Sections ",""); myTemplateholder = myTemplateholder.replace("History","<div id='templateHeader'>History</div>"); myTemplateholder = myTemplateholder.replace("ROS","<div id='templateHeader'>ROS</div><br>"); myTemplateholder = myTemplateholder.replace("Exam","<div id='templateHeader'>Exam</div>"); myTemplateholder = myTemplateholder.replace("ICD9","<div id='templateHeader'>ICD9</div>"); for(child in children) { myTemplateholder = myTemplateholder.replace(" "+children[child],children[child]+"<div id='questionRadio'><input type='radio' name='answer' value='Y' /> Y <input type='radio' name='answer' value='N' /> N <input type='radio' name='answer' value='NA' /> N/A<br /></div>"); } $('#showMe').html(myTemplateholder); } I'm totally stuck! Thanks for bearing with a newbie - any help would be greatly appreciated. Hi, I want to write a javascript program which will redirect the user from a welcome page to an an intro page when a cookie is found. If there are not cookies found, the welcome page is loaded but a cookie is written so that next time the user visits the page, he will be redirected to the intro page automatically. This program would allow only new visitor to view the welcome page and other visitors to skip the welcome page to be brought to the intro page right away. I am a newbie and here is the code which I have though of so far. Can someone expand on it? Thanks The Apprentice Code: window.onload = pageInit; function pageInit(){ var visited = ""; if (document.cookie !=""){ window.location = "introPage.htm"; } else{ setCookie(); } function setCookie(){ document.getElementById("click").onclick = cookie; var expireDate = new Date(); expireDate.setMonth(expireDate.getMonth() + 6); Hello everyone I am trying to receive the output of an array from a text input here is the code that I am attempting to do but it is not displaying the output January Here is the code example [CODE] <html> <script type ="text/javascript"> <!-- function coms(str){ var myArray = new Array(); myArray[0] = ["January"]; var index = 0; for(var i = 0; i < myArray.length; i++){ index; if(myArray[i] == "January"){ index i; } if(str.length == myArray[i]){ document.write(str); } } } </script> <body> <form> Panel:<input type="text" name="panel" onkeyup="coms(this.value)" /> <div id="read"><p>Data is displayed here</p></div> </form> </body> </html> [CODE] Any tips to make this possible are welcome thank you kindly Hi, I have a dynamic JS table and the user can add several rows then populate rows with data. There are 4 columns in table. First row, first two columns have JQuery calendar. Third column has populated select list. Fourth column, first row has JS function to ensure that user enters integer/decimal with corresponding alert for incorrect entry. Two things I want to do: 1. Populate added rows with JQuery calendars and integer/decimal alert. 2. Capture added rows and data from user entries so that information can be sent to database via ColdFusion programming. The following is the js code I am using: For the datepicker I linked to an in-house URL so this is the function - Code: $(function() { $("#startdate").datepicker(); $("#enddate").datepicker(); $("#RcompStart").datepicker(); $("#RcompEnd").datepicker(); }); </script> The objects (inputs) for the above are Code: <td><input style="width: 70px" type="text" id="startdate"></td> <td><input style="width: 70px" type="text" id="enddate"></td> For the numeric alert the function is Code: <script type="text/javascript"> function checkQuarters( fld ) { var val = parseFloat(fld.value); if ( isNaN(val) || ( val*4 != Math.floor(val*4) ) ) { alert("Value must be a numeric and a multiple of 0.25"); return false; } return true; } </script> The object (input) for the above is Code: <td><p> <form style="width: 5px; height: 1px;"> <input type="text" name="No. of Hours" id="No. of Hours" style="width: 70px;" onblur="checkQuarters(this);" /> </form> </td> And to add and remove rows the function is Code: <script language="Javascript" type="text/javascript"> /*<![CDATA[*/ var new_rows=new Array(); var row_count=0; function addRow() { var tbl = document.getElementById('ReqDtTbl'); new_rows[row_count]=new Array(); var lastRow = tbl.rows.length; var iteration = lastRow; if (lastRow>7){ return;} var row = tbl.insertRow(lastRow); var cellLeft = row.insertCell(0); var textNode = document.createElement('input'); textNode.size = 7; textNode.name = 'startdate' + iteration; cellLeft.appendChild(textNode); new_rows[row_count]['cell']=textNode; var cellRight = row.insertCell(1); var el = document.createElement('input'); el.type = 'text'; el.name = 'enddate' + iteration; el.id = 'enddate' + iteration; el.size = 7; new_rows[row_count]['cell2']=el; cellRight.appendChild(el); // the last cell! var cellRightSel = row.insertCell(2); var sel = document.createElement('select'); sel.name = 'TypeHrs' + iteration; sel.options[0] = new Option('-Select-', '""'); sel.options[1] = new Option('Comp Time', 'Comp Time'); sel.options[2] = new Option('Credit Hrs', 'Credit Hrs'); sel.options[3] = new Option('Overtime', 'Overtime'); sel.options[4] = new Option('Rel Comp', 'Rel Comp'); cellRightSel.appendChild(sel); new_rows[row_count]['cell3']=sel; var cellRight = row.insertCell(3); var el = document.createElement('input'); el.type = 'text'; el.name = 'No. of Hours' + iteration; el.id = 'No. of Hours' + iteration; el.size = 7; cellRight.appendChild(el); new_rows[row_count]['cell']=el; row_count++; } function removeRow() { // grab element again var tbl = document.getElementById('ReqDtTbl'); // grab length var lastRow = tbl.rows.length; // delete last row if there is more than one row if (lastRow > 2) tbl.deleteRow(lastRow - 1); } /*]]>*/ </script> The buttons for this function are Code: <input type="button" value="Add a row" onclick="addRow('ReqDtTbl',5)";/> <input type="button" value="Remove a row" onclick="removeRow();" /> That's it. Thanks - John Could someone take a look at this and tell me what I am doing wrong please? I have an onSubmit function that calls the following code. It works fine spitting out the return values, but the section with the "textareas for" statement is displayed after everything else. (I understand why) However, I want it to display in the order with the rest of the fields. Ideally it should be a part of the "inputArray for" statement. Is there an easy way to join these two for statements and spit everything out in the order from the original form? Thanks Code: <script> function showComposer() { var textstring = ''; var textAreaArray = ''; var textareas = document.repairform.getElementsByTagName("textarea"); var inputArray = document.repairform.getElementsByTagName("input"); for (i=0;i<inputArray.length;i++) { if (inputArray[i].getAttribute('class') == 'info') { textstring += "<table><tr><td><strong>" + inputArray[i].name + " : </strong></td>" + "<td>" + inputArray[i].value +"</td></tr></table>"; } else if((inputArray[i].getAttribute('type') == 'text') || (inputArray[i].getAttribute('type') == 'radio' && inputArray[i].checked)) { textstring += "<table><tr><td><strong>" + inputArray[i].name + " : </strong></td>" + "<td>" + inputArray[i].value +"</td></tr></table>"; } } for (i=0;i<textareas.length;i++) { textAreaArray += "<table><tr><td><strong>" + textareas[i].name + " : </strong></td>" + "<td>" + textareas[i].value +"</td></tr></table>" + '\n'; } var stringArray = textstring.concat(textAreaArray); var composer = new NKMailComposer(); composer.setRecipient(""); composer.setSubject("ESTIMATE SHEET AND REPAIR ORDER"); composer.setBody (stringArray, 1); composer.show(); document.repairform.submit(); } </script> Hi Guys, Hope you can help. How do you simply output the current url in the browser i.e if i am in google.com I want google.com outputted and so on. Also on multilanguage sites if my url is say www.mydomain.com/en/about.html or http://www.mydomain.com/en/animals/h...stallions.html I want to be able to manipulate the url so I can change en to fr for example when I jump between english and french pages. I want users to be able to switch the language of that particular page by clicking a link. I need to be able to switch segment one of the url (en,fr,de etc...)dynamically somehow instead of hardcoding a link into each page. Any ideas? THANKS I've tried a couple of different scripts, and I'm getting the same result, so I know I must just be missing something. I'm very new to this, so I'm not figuring it out. I want a text box to show the results of an increment counter. Every time I click a button, the number in the text box increments by one. I know it sounds simple, but it's not working. Help? My code is below: Code: <style type = "text/css"> .tbsize { width: 30px; border: 3px; padding: 10px } </style> <script type="text/javascript"> var i=0; function increase() { ++i; } </script> </head> <body> <div id = "tbsize" class = "tbsize"> <form onsubmit = "return false" action = ""> <table> <td><input type = "text" id = "addone" /></td> <td><input type = "submit" value = "Click to add One" onclick="increase()"></td> </table> </form> </div> </body> </script> Hi, I need to show the results in a proper manner. now I'm testing these results as a alert. But I need to show them in a table and I have to sort them according to the ascending order. Do you have any suggestions? hi, I'm a new guy to computer science and info system and I am taking an intro class to it right now. I was asked to make a simple "enter the word in the box" quiz and I can't get the output! it's driving me crazy and I get "ur score is [object HTMLInputElement]out of 3" at the bottom when I had it say, "Your score is:".. here is my html coding and no, I'm not asking for anyone to do my homework. I just want to make this work! be easy. NOTE: I'm using Apple over again because I want to get the coding down and then I will change up the quiz and the answers Code: <html> <head> <title> COMSC 100 Assignment 9 by Me </title> <script> function getInputAsText(_id){return document.getElementById(_id).value} function getInputAsNumber(_id){return parseFloat(document.getElementById(_id).value)} function setOutput(_id, _value){document.getElementById(_id).value = _value} function calculate() { // declare all variables var myResult1 var myResult2 var myResult3 var resultAsText // get variable's value myAnswer1= getInputAsText("myResult1") myAnswer2= getInputAsText("myResult2") myAnswer3= getInputAsText("myResult3") // perform concatenation if (myAnswer1.toLowerCase() == " Apple" .toLowerCase()) { score= score + 1 // got this one right myResult1= "correct" } else { myResult1 = "Wrong! It's Apple" } if (myAnswer2.toLowerCase() == "Apple".toLowerCase()) { score= score + 1 // got this one right myResult2 = "correct" } else { myResult2 = "Wrong! it's Apple" } if (myAnswer3.toLowerCase () == "Apple".toLowerCase()) { score = score + 1 //got this one right myResult3 = "correct" } else { myResult3 = "Wrong! It's Apple" } // write output value setOutput("score", "Your score is " + score + "out of 3") setOutput ("myResult1",myResult1) setOutput ("myResult2",myResult2) setOutput ("myResult3",myResult3) } </script> </head> <body> Directions:<br> Answer the three questions and press go <br> Your score will appear<br> Input values:<br> 1. A byte is how many bits?<input id="myResult1"><br> 2.Steve Jobs heads what company?<input id="myResult2"><br> 3.Bill Gates heads what company? <input id="myResult3"><br> <input type="submit" value="go" onclick="calculate()"><br> Output<br> Result #1:<input id= "myResult1" size="25"><br> Result #2:<input id= "myResult2" size="25"><br> Result #3:<input id= "myResult3" size="25"><br> Your sco <input id= "score" size="25"> </body> </html> hi, The following script is supposed to display an output of 5000 or more lines but it stucks if output is more than 3000 lines. so is it possible to achieve such a program..? or does it depend on the computer CPU? thanks PHP Code: <body bgcolor=9999cc> <script> count=0; function yaz() { document.getElementById("kutu").innerHTML=""; document.getElementById("bt").value=""; count=0; for(var a=0;a<=4;a++){ for(var b=0;b<=4;b++){ for(var c=0;c<=4;c++){ for(var d=0;d<=4;d++){ for(var e=0;e<=4;e++){ for(var f=0;f<=4;f++){ for(var g=0;g<=4;g++){ for(var h=0;h<=4;h++){ if((a<b)&(c<d)&(e<f)&(g<h)) { count++; document.getElementById("kutu").innerHTML+=count+"--"+a+".."+b+".."+c+".."+d+".."+e+".."+f+".."+g+".."+h+"<br>"; } } }} }} }} } document.getElementById("bt").value="there are.."+count+"..lines "; } </script> <center> <input type="button"id="bt" value="gooo" onclick="yaz()"> <div id="kutu"align="center" style="border-style:solid;border-width:2;border-color:blue;background-color:pink;width:400;color:green;"> </div> </body> </html> I thought I knew how, but I'm unclear how to get this function to display: "document.getElementById("txtHint").innerHTML=xmlhttp.responseText;" inside the div. Will you show me please? Code: xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var div = document.createElement('div'); div.setAttribute('id', 'txtHint'); div.setAttribute("style","background-color:red;"); div.style.width = '300px'; div.style.height = '100px'; document.getElementById("txtHint").innerHTML=xmlhttp.responseText; //var txt='hello world!'; document.getElementsByTagName('body')[0].appendChild(div); document.getElementById('textHint').innerHTML=txt; } } Hi folks, I have some complex (to me) JS code that displays time and date for the selected location from a drop-down. It can handle half hours and DST adjustments. But it only displays the results in IE. Here is where I call it in html. Code: <font color="#894DFB" size="3"><b><em><span id="wc_clock"></span></em></b></font> <br><span id="wc_date"></span> I have a very basic calculator that I am trying to make that takes info from radio buttons (i.e. 1 for bad 5 for good) and outputs an average or score at the end, but its not working correctly. I have changed the last line to output what the total number is not the average, to see if it is outputting the correct number, and its not... It says "[object HTMLInputElement]"... Any thoughts will be greatly appreciated! Thanks! Code: function calcScore(){ var op1 = document.getElementsByName('form[q1]'); var op2 = document.getElementsByName('form[q2]'); var op3 = document.getElementsByName('form[q3]'); var op4 = document.getElementsByName('form[q4]'); var op5 = document.getElementsByName('form[q5]'); var op6 = document.getElementsByName('form[q6]'); var op7 = document.getElementsByName('form[q7]'); var op8 = document.getElementsByName('form[q8]'); var op9 = document.getElementsByName('form[q9]'); var op10 = document.getElementsByName('form[q10]'); var op11 = document.getElementsByName('form[q11]'); var op12 = document.getElementsByName('form[q12]'); var op13 = document.getElementsByName('form[q13]'); var op14 = document.getElementsByName('form[q14]'); var op15 = document.getElementsByName('form[q15]'); var op16 = document.getElementsByName('form[q16]'); var op17 = document.getElementsByName('form[q17]'); var op18 = document.getElementsByName('form[q18]'); var op19 = document.getElementsByName('form[q19]'); var op20 = document.getElementsByName('form[q20]'); var op21 = document.getElementsByName('form[q21]'); var op22 = document.getElementsByName('form[q22]'); var op23 = document.getElementsByName('form[q23]'); var op24 = document.getElementsByName('form[q24]'); var op25 = document.getElementsByName('form[q25]'); var op26 = document.getElementsByName('form[q26]'); var op27 = document.getElementsByName('form[q27]'); var op28 = document.getElementsByName('form[q28]'); var op29 = document.getElementsByName('form[q29]'); var op30 = document.getElementsByName('form[q30]'); var op31 = document.getElementsByName('form[q31]'); var totalscore = document.getElementById('score'); totalscore.value = 0; totalscore.value = parseInt(totalscore.value); var totalnum = document.getElementById('score1'); totalnum.value = 0; totalnum.value = parseInt(totalnum.value); for (var i=0; i < op1.length; i++) { if (op1[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op1[i].value); } } for (var i=0; i < op2.length; i++) { if (op2[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op2[i].value); } } for (var i=0; i < op3.length; i++) { if (op3[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op3[i].value); } } for (var i=0; i < op4.length; i++) { if (op4[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op4[i].value); } } for (var i=0; i < op5.length; i++) { if (op5[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op5[i].value); } } for (var i=0; i < op6.length; i++) { if (op6[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op6[i].value); } } for (var i=0; i < op7.length; i++) { if (op7[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op7[i].value); } } for (var i=0; i < op8.length; i++) { if (op8[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op8[i].value); } } for (var i=0; i < op9.length; i++) { if (op9[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op9[i].value); } } for (var i=0; i < op10.length; i++) { if (op10[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op10[i].value); } } for (var i=0; i < op11.length; i++) { if (op11[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op11[i].value); } } for (var i=0; i < op12.length; i++) { if (op12[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op12[i].value); } } for (var i=0; i < op13.length; i++) { if (op13[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op13[i].value); } } for (var i=0; i < op14.length; i++) { if (op14[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op14[i].value); } } for (var i=0; i < op15.length; i++) { if (op15[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op15[i].value); } } for (var i=0; i < op16.length; i++) { if (op16[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op16[i].value); } } for (var i=0; i < op17.length; i++) { if (op17[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op17[i].value); } } for (var i=0; i < op18.length; i++) { if (op18[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op18[i].value); } } for (var i=0; i < op19.length; i++) { if (op19[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op19[i].value); } } for (var i=0; i < op20.length; i++) { if (op20[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op20[i].value); } } for (var i=0; i < op21.length; i++) { if (op21[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op21[i].value); } } for (var i=0; i < op22.length; i++) { if (op22[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op22[i].value); } } for (var i=0; i < op23.length; i++) { if (op23[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op23[i].value); } } for (var i=0; i < op24.length; i++) { if (op24[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op24[i].value); } } for (var i=0; i < op25.length; i++) { if (op25[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op25[i].value); } } for (var i=0; i < op26.length; i++) { if (op26[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op26[i].value); } } for (var i=0; i < op27.length; i++) { if (op27[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op27[i].value); } } for (var i=0; i < op28.length; i++) { if (op28[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op28[i].value); } } for (var i=0; i < op29.length; i++) { if (op29[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op29[i].value); } } for (var i=0; i < op30.length; i++) { if (op30[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op30[i].value); } } for (var i=0; i < op31.length; i++) { if (op31[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op31[i].value); } } totalscore.value = totalnum; } Hi! I'm very new to javascript and a bit stuck with trying to calculate values from functions together. Let's say I have three functions. Each function is given a value and the goal is to calculate all the values together in a variable. This is what I have so far: Code: function numberAdd1 () { addValue = 1; return.addValue; } function numberAdd2 () { addValue = 2; return.addValue; } function numberAdd3 () { addValue = 3; return.addValue; } How would I now calculate the return value of each funtion together and store the result in a variable? I want to write a code. in which I select the AC Temperature By Radio Buttons. then I observe the Saving energy by Bar Graph with out submitting the Form. As I change the Input, automatically, Output should change what should be code in HTML or Javascript so that I may observe effect of the change of Temperature on saving energy. thanks. |