JavaScript - Can I Solve An Array Of Equations With A Variable Input?
the title kind of sums it up... if I have an array of equations (I'm guessing they should be strings but they don't have to be) and a user-defined variable can that variable be used for the "x" in the equations? I already did the easy part ...
Code: <!DOCTYPE html> <html> <head> </head> <body> <input onkeyup="solve(this.value)" /><br> <input id="box0" /><br> <input id="box1" /><br> <input id="box2" /><br> <script type="text/javascript"> var equations=["(x*9/5)+32","x+273.15","x-50*(8/13)"] function solve(val){ for (var i = 0; i < equations.length; i++) { document.getElementById("box"+i).value= //ummm... } } </script> </body> </html> Similar TutorialsHello I'd really appreciate some help please, no other forum seems to have an answer for this. Example : I have a file called values.asp and in that file are 100 different variables all assigned a specific number. I also have a results.asp file or a simple html page. The target is to read a specific variable in the values.asp file and then display it in another asp file or standard HTML file using Javascript's document.write(variablename); method. So in other words, i wish to fetch a specific variables value from values.asp and show it in another asp file or a simple html file using javascript. Your help will be very much appreciated. Thanks! Ron Hi, i have an input value array for customer ids, i also need to make a copy of that array into another input element on submit to use for another process. So far here is what i have come up with regarding the js the current html is this Code: <!-- original input --> <input id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $commissions[$i]['id'];?>" onclick="isChecked(this.checked);" type="checkbox" /> <!-- this is new html input which is outside the $i loop that i need a copy of cid[] stored on submit <input type="hidden" name="ids[]" onsubmit="valueTovalue();" /> <!-- here is the js so far --> <script type="text/javascript"> function valueTovalue() { var valin = document.adminForm.cid.value; //cid is the array cid[] document.adminForm.ids.value = valin; //copy the array to the new input element array ids } </script> so basically if they click 1 cid then ids will also show 1, if they click all cid then ids will show all as well. will that work the way i have it, am i even close here.. thanks update: what i have seems to work fine for text values or string values but not for arrays, what am i missing that it wont copy an array? Array ( [cid] => Array ( [0] => 1 ) [task] => remarksonly [remark] => hhhyyy [boxchecked] => 1 [ids] => Array ( [0] => ) ) am i getting closer lol Code: function valueTovalue() { var valin = cid.concat; document.adminForm.ids.value = valin.concat; return(true); this has to be close i hope Code: document.adminForm.ids.value = [].concat(document.adminForm.cid); What I have to do is, "Ask for number1, ask for number2 and show them added, subtracted and multiplied." Here is my code, what's wrong? <script type="text/javascript"> var number1= parseFloat ( window.prompt ("What is the first number?","")) || 0; var number2= parseFloat ( window.prompt ("What is the second number?","")) || 0; var addition= num1*1 + num2*1; var subtraction= num1*1 - num2*1; var multiplication= num1*1 * num2*1; document.write (Addition is: " num1+" + "+num2+"="+ addition); document.write (subtraction is: " num1" + "+num2+"="+ subtraction); document.write (muliplication is: " num1" + "+num2+"="+ multiplication); </script> I am creating a program that will give you the nutritional value's of the McDonalds menu and I am in need of help to gather the information from the input bar and turn that into a Javascript variable using javascript, the code below is the form, input box, and the case/switch that I would like to use to create this, Thanks in advance! Code: <form id="help"> <input class="sb" id="life" type="text" placeholder="What food would you like to check?"> <button type="submit" class="button">Submit</button> </form> <div id=cci> <script> var item = document.getElementById("help"); var food = item.toLowerCase(); switch (food) { case 'big mac': document.write('<br><br><br>'); document.write('Big Mac'); document.write('<br><br>'); document.write('Calories: 530'); document.write('<br>'); document.write('Carbohydrates (g): 47'); document.write('<br>'); document.write('Total Fat (g): 27'); document.write('<br>'); document.write('Cholesterol (mg): 85'); document.write('<br>'); document.write('Dietary Fiber (g): 3'); document.write('<br>'); document.write('Sugars (g): 9'); document.write('<br>'); document.write('Protein (g): 24'); break; default: document.write('<br><br><br><br>'); document.write(food); document.write('<br><br><br>'); document.write('The food is not recognized'); document.write('<br><br>'); document.write('Double check your spelling'); break; } </script> </div> I am making a function where I need to know whether the input is a variable with a string value var foo = "bar"; Function(foo) or if it is a string, wherein it would be the name of an object object = { ThingsInside: function(){code} } Function('object') Code: function Function (object){ if(object is a string){ do this } else if (object is a variable with a string value){ do this } else{ do something else } Because they would be both passed by value, I'm not sure how or if there is a way to tell as they would both just appear as string inputs, right? Hello I'm using simpleCart() javascript shopping machine for my page. The script accepts values in a specific syntax: Code: onclick="simpleCart.add('name=Some name','price=23.4','quantity=1');" But because the price of the product is not always the same but comes up after previously made calculations, i want to parse the values in simpleCart() through another function. I have made the following one which gets the price from a textbox (resultAlmires) of a form (Almires), then converts it to american format (. instead of ,) makes it have one decimal only and finally parse it to simpleCart() with the use of a variable. However it doesn't seem to work: Code: function addAlmiri() { var timi = document.Almires.resultAlmires.value; timi = timi.replace(/\,/,"."); timi = timi.toFixed(1); simpleCart.add( 'name = Some name' , 'price = timi' , 'quantity = 1' ); } Any help? Hi all, I'm having some trouble with the this... I have a PHP based calendar where the cells will change color depending on the number of clicks.. this all works fine, but is pointless if I can't send the outcome along in an email. I can do this with PHP but first need to get the values into a hidden field. This is what I have: Code: <script type="text/javascript"> function countClicks (obj){ if (!obj.count) { obj.count = 0; } obj.count++; if (obj.count > 4) {obj.count = 1}; if(obj.count == 1){ obj.style.color='#FFFFFF'; obj.style.backgroundColor='#66CC33'; obj.parentNode.style.backgroundColor='#66CC33'; document.getElementById("availability").value='Available'; } if (obj.count == 2){ obj.style.color='#FFFFFF'; obj.style.backgroundColor='#FF0000'; obj.parentNode.style.backgroundColor='#FF0000'; document.getElementById("availability").value='Not Available'; } if (obj.count == 3){ obj.style.color='#FFFFFF'; obj.style.backgroundColor='#FFCC33'; obj.parentNode.style.backgroundColor='#FFCC33'; document.getElementById("availability").value='Working'; } if (obj.count == 4){ obj.style.color='#000000'; obj.style.backgroundColor='#FFFFFF'; obj.parentNode.style.backgroundColor='#FFFFFF'; document.getElementById("availability").value='Not Set'; } } </script> and... Code: echo "<input type=\"hidden\" name=\"availability\" id=\"availability\" value=\"\">"; All I'm trying to do is populate value with either 'available', 'not available', 'working' or 'not set'... however, it is worth noting that each cell may have a different value, e.g. 1 cell might be working while the other is not available... so i need to pass the values of all the cells. Can anyone help me out here. Many thanks, Greens85 Hi, my first question on this forum is I hope a simple one. I have an input text field that I would like to have either the user fill out but also I would like to be able to fill it with text, which I can do, via javascript or a variable which I don't seem to be able to manage. I have tried lots of options, converting to a string first and much more but it will not work, maybe it is a syntax error or maybe I am just doing it plain wrong. I think it should be simple but I have only been using javascript for a few weeks so who knows, hopefully one of you! Here is my code for displaying a variable which does not work: Code: <html> <head> <script type="text/javascript"> function myfunction() var mynumber = 101; document.getElementById("myinput").value = mynumber; </script> </head> <body> <p id="demo">Web Page 1</p> <button type="button" onclick="myfunction()">JS</button> <input type="text" value="00000000" id="myinput"> </body> </html> I would be very grateful for any help. Thanks Simon Hi! I am quite new to the world of JavaScript as I have done basic corse for it... and I have learnt that best way to understand it is to play around with it... but now I am stuck with on of the problem!! Problem: How can we assign text box input values by user to a variable and display that variable back on another element of the same HTML document(dynamically)... Conditions: The value has to be stored as a JavaScript variable only. No server-side script is to be used and has to be done locally. Please help! hi guyz i do have a problem in passing javascript variable to <input type=hidden value=""> here's my code: <?php while ($row = mysql_fetch_array($result)) { ?> <script type="text/javascript"> function viewcodec(){ var randomValueCodec = randomString(5, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'); document.getElementById('commentMarkCodeCompCodec-'+<?php echo $row['p_id'];?>).innerHTML = randomValueCodec; document.getElementById('commentMarkCodeComp-'+<?php echo $row['p_id'];?>).innerHTML = randomValueCodec; } </script> <form action="" method="post" name="postsForms"> <div class="commentBox" align="right" id="commentBox-<?php echo $row['p_id'];?>" <?php echo (($comment_num_row) ? '' :'style="display:none"')?>> <input type=text id="commentMarkname-<?php echo $row['p_id'];?>" name="commentmarkname" class="commentMarkname" size="35" maxlength="20"> <textarea class="commentMark" id="commentMark-<?php echo $row['p_id'];?>" name="commentmark" cols="60"></textarea> <input type=text id="commentMarkcode-<?php echo $row['p_id'];?>" name="commentmarkcode" class="commentMarkcode" size="35" maxlength="20"> <br clear="all" /> <span id='commentMarkCodeCompCodec-<?php echo $row['p_id'];?>'><b><script type="text/javascript">viewcodec();</script></b></span> <input type="hidden" id="commentMarkCodeComp-<?php echo $row['p_id'];?>" name="commentMarkCodeComp" value=""> <br clear="all" /> <br clear="all" /> <a id="SubmitComment" style="float:right" class="small button comment"> Comment</a> </div> </form> <?php } ?> Hi I have problem to manipulate my form with array. I want to copy my input from one input to other input but it didnt work. i did explore the usage of document.myForm.feed[3].value but it gave me error. Pleaseee help? Thanks script sample: <form name=myForm> <input name=feed[] onBlur=duplicate(this)> <input name=feed[] onBlur=duplicate(this)> <input name=feed[] onBlur=duplicate(this)> <input name=feed[] onBlur=duplicate(this)> <input name=feed[] onBlur=duplicate(this)> <input name=feed[] onBlur=duplicate(this)> <input name=feed[] onBlur=duplicate(this)> <input name=feed[] onBlur=duplicate(this)> <input name=copier[] onBlur=sendback(this)> <input name=copier[] onBlur=sendback(this)> <input name=copier[] onBlur=sendback(this)> <input name=copier[] onBlur=sendback(this)> <input name=copier[] onBlur=sendback(this)> <input name=copier[] onBlur=sendback(this)> <input name=copier[] onBlur=sendback(this)> <input name=copier[] onBlur=sendback(this)> <input name=copier[] onBlur=sendback(this)> </form> <SCRIPT> function duplicate(info) { //this function should copy 'info' to copier input //with the same element location //eg: feed[3] will copy to copier[3], feed[5] will copy to copier[5] //(can be any element insert by user) // the task would be: // 1. to get which element number has been inserted // 2. to get the origin text value // 3. to write the same element position for copier } function sendback(info) { //this function should copy 'info' to feed input //with the same element location //copier[2] will copy to feed[2], copier[3] will copy to feed[3] //(can be any element insert by user) } </SCRIPT> 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 i have tried searching the forums for help but really am getting no where. i am trying to call an array item from an input box. the input is all numbers. the arrays are v + numbers. i cannot seem to figure out how to get the item from the array. eg Code: var v00501 = ["HOLTSVILLE,I R S SERVICE CENTER","NY","631","-5","Y"] var v00544 = ["HOLTSVILLE,IRS SERVICE CENTER","NY","631","-5","Y"] var v00601 = ["ADJUNTAS,JARD DE ADJUNTAS,URB SAN JOAQUIN","PR","787/939","-4","N"] function pop() { var zipv = "v" + myform.Zip.value +"[0]"; alert(zipv); } or Code: function pop() { alert(pop1()); } function pop1() { return "v" + myform.Zip.value +"[0]"; } so for this if the user typed in 00501 i get v00501[0] no matter what i try. i want HOLTSVILLE,I R S SERVICE CENTER to be returned or whatever item i am calling for. this all has to be on client side as i dont have server access so the zip codes are all set up as arrays in a seperate file. i really dont know alot about javascript but i am learning. any help on how i can accomplish this would be appreciated. hello, I have a text input box where users can input values separated by a line break. What I need to do is to take those values and put them all into an array once they hit "submit". I can do this one line at a time, but I would like to be able to do it all in one hit. Can it be done in javascript? thanks in advance... Hi, I'm struggling with all this DOM stuff so I hope someone can help. I have a form with multiple input fields and I'm trying to identify the specific input field that is in focus so that I can display a relevant status bar message. I have a message array with various entries in it and I'm calling a showStatus() function with an onfocus function from the form itself e.g. The code in the input form = Code: <input type="text" name="first" size="31" maxlength="20" class="entry" onfocus="showStatus()"/> The showStatus() function so far is = Code: function showStatus() { var message = ['Please provide your First Name.', plus loads of other properley formatted status messages......] var x=document.getElementById().focus(); window.status = message[x]; } I'd like to access the array variable of the item that is in focus not only for the message but also for an onblur function to validate input. Any ideas? My thanks R Hi, what would be the best way to have a hidden array of possible text directed at a textarea and then if something is not within that array "onfocus", a certain select option is chosen within that form? Thanks I am currently trying to check using javascript whether a php array contains a variable, and if it does then display a message. Any help would be much appreciated. I have written the following code... Code: <?php //php which sets users array to the results of the sql $selectquery = "SELECT Username FROM User"; $selectresult = mysql_query($selectquery); while ($row = mysql_fetch_array($selectresult)){ $users[] = $row['Username']; } ?> <script language="javascript" type="text/javascript"> function verifyUsername(array_var){ var user = document.getElementById("username").value; for(var i=0; i<array_var.length; i++){ if(array_var[i] == user){ document.getElementById("usernameerror").textContent = "already in array"; } } } </script> //html code for the form Username: <input type="text" name="username" id="username" onblur="return verifyUsername(<?php $users?>)"/> <span id="usernameerror" class="red"></span> |