提问人:Brad Meyer 提问时间:8/4/2021 最后编辑:Brad Meyer 更新时间:8/4/2021 访问量:94
使用 JScript 将选定值从 HTML 中传出
Pass selected values out of HTML with JScript
问:
对 HTML 和 JS 有点陌生。正在为实验室计算机做一些事情。
我已经从这里和这里的一些 SO 来源拼凑了这段代码,但很快就要结束了。
我正在尝试做什么:让我的用户从表中的各个行中进行选择。这些数据中的行在页面的下半部分显示给用户进行确认。我认为需要将这些参数传递给用 VBScript 编写的更大方法(用于 Biomek 液体处理器)。
我传递的变量是主程序中的全局变量,但该程序没有“看到”变量通过选择哪一行而变化。
无论我做什么,我都无法以数字形式将变量 A) 或 B) 取出(我需要它是数字)。我要么没有得到全局变量更改,要么只是一个字符串被传递出去。
我认为一旦我确定了运算符选择的值,并且可以将该值传递给其他东西,我就可以传递出去,但现在我所能分配的只是变量的字符串名称,而不是它后面的值。
有问题的脚本:
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
<script language="javascript" type="text/javascript">
function showRow(row)
{
var x=row.cells;
document.getElementById("Volume1").value = x[0].innerHTML;
document.getElementById("Volume2").value = x[1].innerHTML;
}
function ChangeColor(row, highLight)
{
if (highLight)
{
row.style.backgroundColor = '#dcfac9';
}
else
{
row.style.backgroundColor = 'white';
}
}
</script>
</head>
<body>
<FORM METHOD="GET" ACTION="http://localhost">
<table id="myTable" cellspacing="3"
<thead>
<tr>
<th>Volume 1</th>
<th>Volume 2</th>
</tr>
</thead>
<tbody>
<tr onclick="javascript:showRow(this);"
onmouseover="javascript:ChangeColor(this, true);"
onmouseout="javascript:ChangeColor(this, false);" >
<td>88.4</td>
<td>100</td>
</tr>
<tr onclick="javascript:showRow(this);"
onmouseover="javascript:ChangeColor(this, true);"
onmouseout="javascript:ChangeColor(this, false);" >
<td>22.8</td>
<td>44</td>
</tr>
<tr onclick="javascript:showRow(this);"
onmouseover="javascript:ChangeColor(this, true);"
onmouseout="javascript:ChangeColor(this, false);" >
<td>73.2</td>
<td>125</td>
</tr>
<tr onclick="javascript:showRow(this);"
onmouseover="javascript:ChangeColor(this, true);"
onmouseout="javascript:ChangeColor(this, false);" >
<td>13.64</td>
<td>17</td>
</tr>
</tbody>
</table>
<br>
<br>
Volume 1 is:<input type="text" id="Volume1" />
<br>
Volume 2 is:<input type="text" id="Volume2" />
<br>
<br><br><br>
<INPUT TYPE="submit" NAME="submitButton__" VALUE="CONTINUE" />
</FORM>
</body>
</html>
过往成功案例:过去,我已经能够完成我正在尝试的事情。在下面的代码片段中,我成功地能够从我的主程序中“看到”变量“user_NumberSamples”、“user_Replicates”和“user_DiluteSample”的值。因此,虽然这在过去有效,但我当前的用例略有不同,正如您将看到的:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBScript">
<!-- ***** Put scripts for handling page elements here -->
</SCRIPT>
<BODY BGCOLOR="BlanchedAlmond">
<FORM METHOD="GET" ACTION="http://localhost">
<h1 style="text-align:center;">TEST METHOD</h1>
<TABLE BOARDER=1>
<TR>
<P><h3 style="text-align:center;">Please enter all of the required information</h3></TD>
</P>
<BR>
<p>
</p>
<TR>
<TR><strong>Enter the number of samples being tested: </strong></TR>
<TR><INPUT TYPE=text NAME="user_NumberSamples" SIZE=2 VALUE="48">
</TR>
<br>
<br>
<p>
<TR><strong>Please select the number of REPLICTES: </strong><TR>
<select name="user_Replicates" size="1">
<option>3</option>
<option>2</option>
<option>1</option>
</select></BR>
<TR>
</TABLE>
<br>
<tr><strong>Perform a pre-dilution of Samples 1:10?:</strong></tr>
<input type="radio" id="False" name="user_DiluteSample" value="False" checked>
<label for="False">False</label>
<input type="radio" id="True" name="user_DiluteSample" value="True">
<label for="True">True</label><br>
<p>NOTE: Diluting samples will make all replicates come from the same dilution plate, i.e. technical replicates<p>
<INPUT TYPE="submit" NAME="submitButton__" VALUE="Click To Continue">
</FORM>
</BODY>
</HTML>
我尝试了很多我无法真正表达的事情,几个小时,所以现在是时候问一些专家了。谢谢!
答: 暂无答案
评论