Submit button not working
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.
Submit button not calling functions properly
Here it is...My issue is in the actual javascript. I'm not sure if I'm going about this the right way.
<!DOCTYPE html PRIVATE Copyright of UNC Charlotte>
<head>
<script type="text/javascript">
function getgmSize(form)
{
//var theForm=documents.forms["ngs1form"];
var gsize=form.gsize.value
//var gsize=0
if(gm.value!="")
{
gsize=parseInt(gsize.value);
}
return gsize;
}
function getRunTime(form)
{
var runtime = new Array();
run_time["r4 FLX"]=10;
run_time["t- g2 75bp SE"]=168;
run_time["t- g2 75bp PE"]=168;
run_time["t- g2 100bp SE"]=228;
run_time["t- g2 100bp PE"]=228;
run_time["t- hp 100bp SE"]=228;
run_time["t- hp 100bp PE"]=228;
run_time["abs"]=160;
run_time["hh-9"]=190;
run_time["pbj"]=3;
run_time["it-6"]=3;
var run_time=0;
//var theForm=document.forms["ngs1form"];
run_index=selectedPlatform.selectedIndex;
var selectedPlatform = ngs1form.elements["Technology"].selectedIndex;
if(selectedPlatform >0)
{
var sel_platform_value=selectedPlatform.options[index].value;
run_time=run_time[selectedPlatform.value];
return run_time;
}
else{
alert('Please select a platform');
}
function getlength(form)
{
var read_length= new Array();
read_length["r4 FLX"]=400;
read_length["t- g2 75bp SE"]=75;
read_length["t- g2 75bp PE"]=75;
read_length["t- g2 100bp SE"]=100;
read_length["t- g2 100bp PE"]=100;
read_length["t- hp 100bp SE"]=100;
read_length["t- hp 100bp PE"]=100;
read_length["abs"]=50;
read_length["hh-9"]=40;
read_length["pbj"]=10000;
read_length["it-6"]=100;
var length=0;
//var theForm =document.forms["ngs1form"];
var selectedPlatform=document.ngs1form.elements["Technology"];
length=read_length[selectedPlatform.value];
document.write(length);
}
function getRuns()
{
var runs = new Array();
reads_run["r4 FLX"]=1000000;
reads_run["t- g2 75bp SE"]=30000000;
reads_run["t- g2 75bp PE"]=60000000;
reads_run["t- g2 100bp SE"]=25000000;
reads_run["t- g2 100bp PE"]=50000000;
reads_run["t- hp 100bp SE"]=168750000;
reads_run["t- hp 100bp PE"]=337500000;
reads_run["abs"]=0;
reads_run["hh-9"]=0;
reads_run["pbj"]=50000;
reads_run["it-6"]=100000;
var rpruns=0;
//var theForm=document.forms["ngs1form"];
var selectedPlatform=document.ngs1form.elements["Technology"];
rpruns=reads_run[selectedPlatform.value];
return rpruns;
}
function getgmSize(form)
{
//var theForm=documents.forms["ngs1form"];
var gsize=form.gsize.value
//var gsize=0
if(gm.value!="")
{
gsize=parseInt(gsize.value);
}
return gsize;
}
function getcv(form)
{
//var theForm=documents.forms["ngs1form"];
var cv=form.cv.value
//var cv=0
if(cv.value!="")
{
cv=parseInt(cv.value);
}
return cv;
}
function calculate(form)
{
form.results.value = (getgmSize*getcv)/(getRuns*getlength);
//var divobj = document.getElementById('totalLanes');
//document.write(lanes);
//divobj.style.display='block';
//divobj.innerHTML = "Estimated number of lanes required"+lanes;
}}
</script>
</head>
<body>
<form name="ngs1form" method="post">
<div id="topbar" class="transparent"></div>
<div id="blueleftbutton"> <a href="index2.html"><img alt="home" src="images/home.png" width=100% height=100%></a></div><div class="center" id="title">Lane Calculator</div></br></br>
<div id="tributton"><div class="links"><a href="ngs1.html">Lanes</a><a href="ngs2.html">Coverage</a><a href="stats.html">Platform Stats</a></div></div></br>
</div>
<span class="graytitle">Genome Size (Mb)</span>
<ul class="pageitem">
<li class="bigfield"><input placeholder="Enter Genome size" type="text" id="gensize"/></li>
</ul>
<span class="graytitle">Platform</span>
<ul class="pageitem">
<li class="select">
<select id="popup" name="Technology" size="1">
<option value="Select"> - Select your Platform - </option>
<option value="0">r4</option>
<option value="Il">Il SE</option>
<option value="IlPE">Il PE</option>
<option value=" SE">Ip SE</option>
<option value="Ip PE">Il</option>
<option value="I 100bp SE">Illbp SE</option>
<option value="Ilq 100bp PE">Il 100bp PE</option>
<option value="A">AD</option>
<option value="Hee">pe</option>
<option value="Po">Po</option>
<option value="I">It</option>
</select>
<span class="arrow"></span>
</li>
</ul>
<span class="graytitle">Coverage</span>
<ul class="pageitem">
<li class="bigfield"><input placeholder="Enter required" type="text" id="coverage" name="coverage"/></li>
</ul>
<center>
<span class="button"></span>
<ul class="pageitem">
<li class="button"><input name="results" type="submit" value="Submit" onclick="javascript:calculate(this.form)"/></li>
</ul>
<div>
<span class="graytitle">Results</span>
<ul class="pageitem">
<li class="bigfield"><input type="text" name="results"/></li>
</ul>
</div>
</form>
</body>
</html>
Reply to Submit button not working
Okay, that definitely means I've been looking at this too long. I missed all of those. Okay, that makes sense. I should keep the arrays consistent correct?
Does it matter if I call more than one javascript in the head part of the document???
Thank you again jamesbcox
Will you be able to reply if I need more help???:)
Submit and Alert not working
I've edited the code and fixed the errors (to my knowledge). Still not working. I've even reduced to one function with an alert and it still does not work.
I want to give the user two text fields and a drop down list. based on the selection of the list and the values, there will be a number generated.
Here is the code:
<html xmlns="http://www.w3.org/1999/xhtml">
<!--© 2011 UNC Charlotte | All Rights Reserved.
function getGenomeSize()
{
//var theForm=documents.forms["ngs1form"];
var gensize=form.gensize.value
//var gensize=0
if(size.value!="")
{
size=parseInt(gensize.value);
}
return size;
}
function getRunTime()
{
var runtime = new Array();
runtime["454 FLX"]=10;
runtime[" 75bp SE"]=168;
runtime[" 75bp PE"]=168;
runtime["100bp SE"]=228;
runtime[" 100bp PE"]=228;
runtime[" 100bp SE"]=228;
runtime["100bp PE"]=228;
runtime["A"]=160;
runtime["H"]=190;
runtime["P"]=3;
runtime["I"]=3;
//var run_time=0;
//var theForm=document.forms["ngs1form"];
run_index=selectedPlatform.selectedIndex;
var selectedPlatform = ngs1form.elements["Technology"].selectedIndex;
if(selectedPlatform >0)
{
var sel_platform_value=selectedPlatform.options[index].value;
runt_ime=runtime[selectedPlatform.value];
return run_time;
}
else{
alert('Please select a platform');
}
}
function getReadLength()
{
var read_length= new Array();
read_length[" 454 FLX"]=400;
read_length[" 75bp SE"]=75;
read_length["75bp PE"]=75;
read_length[" 100bp SE"]=100;
read_length[" 100bp PE"]=100;
read_length[" 100bp SE"]=100;
read_length[" 100bp PE"]=100;
read_length["A"]=50;
read_length["H"]=40;
read_length["P"]=10000;
read_length["I"]=100;
//var readLength=0;
//var theForm =document.forms["ngs1form"];
var selectedPlatform=document.ngs1form.elements["Technology"];
length=read_length[selectedPlatform.value];
document.write(length);
}
function getRuns()
{
var reads_run = new Array();
reads_run[" 454 FLX"]=1000000;
reads_run["75bp SE"]=30000000;
reads_run["75bp PE"]=60000000;
reads_run["100bp SE"]=25000000;
reads_run["100bp PE"]=50000000;
reads_run[" 100bp SE"]=168750000;
reads_run["Seq 100bp PE"]=337500000;
reads_run["A"]=0;
reads_run["H"]=0;
reads_run["P"]=50000;
reads_run["I"]=100000;
//var rpruns=0;
//var theForm=document.forms["ngs1form"];
var selectedPlatform=document.ngs1form.elements["Technology"];
readsperun=reads_run[selectedPlatform.value];
return readsperun;
}
function getGenomeSize()
{
//var theForm=documents.forms["ngs1form"];
var gensize=form.gensize.value
//var gensize=0
alert (gensize);
}
function getCoverage()
{
//var theForm=documents.forms["ngs1form"];
var coverage=form.coverage.value
//var coverage=0
return coverage;
}
function calculate()
{
lanes= (getGenomeSize()*getCoverage())/(getRuns()*getReadLength());
var divobj = document.getElementById('results');
//document.write(lanes);
//divobj.style.display='block';
divobj.innerHTML = "Estimated number of lanes required"+lanes;
}
Reply to Submit button not working
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.