Trying to get my Submit button to work on this calculator script. I want to retrieve the values for the user and CALCULATE...The button only clears the form and I'm not sure if the functions are calling properly. If there is anyone out there that can help me, please respond and I will post the script.
You're declaring a variable "runtime" then setting a different variable "run_time". An then, after that, you're re-declaring and setting "run_time" to 0. You also didn't close the "getRunTime" function before defining "getlength".
All your variables should be declared in one statement in the top of the function and the function should have clearer structure than you have:
Yes, I subscribed to this post, so if you fix all your formatting and variable names, and it still doesn't work, post the new code and we'll go from there.
To answer your two questions, whether you keep the arrays consistent is up to you. Keeping them consistent would make it easy to copy and paste or to see mistakes. And no doesn't matter how many scripts you call in the head. They are loaded in the order they are written (synchronously).
Last edited by jamesbcox1980; 07-11-2011 at 02:46 PM.
//var theForm =document.forms["ngs1form"];
var reads_run = new Array();
reads_run[" 454 FLX"]=1000000;
reads_run[" 100bp SE"]=168750000;
reads_run["Seq 100bp PE"]=337500000;
var divobj = document.getElementById('results');
divobj.innerHTML = "Estimated number of lanes required"+lanes;
Last edited by bioinfo; 07-11-2011 at 03:11 PM.
Reason: Light reading
I had to place that inside. I commented it back out once I seen all gray. I figured out how to get the button to work but only with one function which is based on the text field. Now I'm trying to see how I can pull the values from the arrays so that the functions can be completed. Thanks a lot. I too am trying to error proof this piece by piece.
Ok here's what I've got. I simply reprogrammed it the way I would do it if it were my page. Notice I created an object to store the measurements instead of an array. Now, I was just guessing on which ones went with which, because you had them labeled differently, so please go over that and fix if necessary. The reason I created the object was a) to make it easier to set and call and b) arrays have more overhead than objects (wouldn't matter so much here as in a larger script).
Couple of things to note:
3. Keep in mind that no two elements in HTML can have the same name or id.
4. if you look closely, I added ".toFixed(2)" to the result so that it would limit the result to 2 decimals. Change this as needed for precision.
5. If you're going to use private DOCTYPE standards, follow them. You're using an unknown HTML doctype, and then in your body you're actually using XHTML. I converted your elements for this.
6. "placeholder" is part of HTML5. Be careful not to mix standards in your documents. Modern browsers "fix" these mistakes at runtime, but it's better not to make them in the first place.
7. ".innerHTML" will not retrieve the value of an input. For that, use document.formName.inputName.value.
also, if you're going to use a private doctype, you need to define the actual location of the doctype standards so that the browser can properly parse the code. otherwise, just use the standard doctype:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
It doesn't mean your document is public, it just means you'll be using the publically published standards. Private means you've got a private standards list published somewhere.
Well, to explain the combined arrays thing in more detail, I actually didn't use an array. The thing about arrays is if you try to use strings for the indices (basically creating an associative array), you're going to create an excess of overhead. Arrays come with several methods and properties that objects don't have (essentially objects only have what you give them).
You can easily create a multidimensional array simply by making any element of an array into an array itself:
Oh ok. Jamesbcox you are a genius..It looks much simpler this way. I see the values are still able to be used as well. That is definitely much easier than what I was doing. I will have to read up on the object function. I will have to try this method for the other two codes I have to do. Thanks for the tutorial also. I have to read over this now so I can get a better understanding.
Thanks again Jamesbcox. I may be bothering you again, if you don't mind.
Well, I'm glad it works for you! If you have any other questions about the way I wrote the code, please let me know. I'd normally like to give you the information you need to figure it out on your own rather than just write it for you, but in this case the problem was really just about organizing your structure.
In order to keep it simple, often times you just need to know what tools are available to you, which takes time and experience. We could have written this script with a single function, however I wanted to show you how the purpose of having functions in the first place is to group repeating code so that a single instance of it can be reused.
If you think about it in terms of the actual process you want your user to have, there's really only a single step once the user clicks the submit button, so your code should reflect that. When I build code, my code starts with an equal number of functions for the number of steps required by the user, and then I'll break out the repeated parts into other functions, such as ajax functions (or data retrieval in general), data conversion functions, animation functions, graphical changes, etc.
One of the big reasons I've become a stickler for strict code structure is that it gives your code a sort of landscape, with landmarks that you can find easily as you scan through your code. When you start building large apps, you can scroll at high speed and find exactly where you need to go without reading a thing. Errors will stick out much better at that point as well.
Anyway, I'm babbling, but again, be sure to ask any questions you might have.