使用 JScript 将选定值从 HTML 中传出

Pass selected values out of HTML with JScript

提问人:Brad Meyer 提问时间:8/4/2021 最后编辑:Brad Meyer 更新时间:8/4/2021 访问量:94

问:

对 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>

我尝试了很多我无法真正表达的事情,几个小时,所以现在是时候问一些专家了。谢谢!

JavaScript HTML 变量参数 传递

评论

0赞 idk wut to put here 8/4/2021
一切似乎都很好。网页有什么问题?
0赞 Brad Meyer 8/4/2021
我需要将数据从 HTML 对话框/GUI 中取出并放入另一个程序中,以便在用户选择表中的正确行后,我可以在下游使用这些数据。该表包含我需要的下游数据。我不知道该怎么做
0赞 idk wut to put here 8/4/2021
在输入字段上放置两个名称属性。它们是截然不同的。提交。会发生什么?
0赞 idk wut to put here 8/4/2021
您将被发送到类似 page.html?name1=value1&name2=value2 的内容。
0赞 Brad Meyer 8/4/2021
@Someone_who_likes_SE 谢谢你的提示,但不幸的是我不太明白。如果你有时间,你能详细说明一下吗?谢谢!ELI5型

答: 暂无答案