0

I want to send some specific data in a table into a specific IP . the other IP is a microcontroller and I need to change every data that has been changed . but the apply/reboot button just send the whole variables . I want to change the button change/reboot tags so that it sends every data in its block instead of the whole data.

<script>
function validateForm()
{
 var x=document.forms[myForm][fname].value;
 if (x==null || x==)
   {
  alert(First name must be filled out); 
  return false; 
   }
 }
 </script>
</head>
<body>
<form name=myForm onsubmit=return validateForm() method=post>
<table>  <tr>
    <td>Device Info :</td>
   <td><input type=text name=dev-info id=1  size="3" value=></td>
   <td>.<input type=text name=dev-info id=11  size="3" value=></td>
   <td></td>
   <td></td>
   <td></td>
   <td></td>
   <td> <input type=submit value=Apply/change></td>
  </tr>
  <tr>
   <td>MAC Adress :</td>
  <td><input type=text name=mac-addr id=2 size="3"></td>
  <td>.<input type=text name=mac-addr id=21 size="3"></td>
  <td>.<input type=text name=mac-addr id=22 size="3"></td>
  <td>.<input type=text name=mac-addr id=23 size="3"></td>
  <td>.<input type=text name=mac-addr id=23 size="3"></td>
  <td>.<input type=text name=mac-addr id=23 size="3"></td>
  <td> <input type=submit value=Apply/change></td>
 </tr>
 <tr>
   <td>IP Adress :</td>
   <td><input type=text name=ip-addr id=3 size="3"></td>
   <td>.<input type=text name=ip-addr id=31 size="3"></td>
   <td>.<input type=text name=ip-addr id=32 size="3"></td>
   <td>.<input type=text name=ip-addr id=33 size="3"></td>
 <td></td>\r\n  <td></td>
 <td> <input type=submit value=Apply/change></td>

 </tr>
 <tr>
   <td>Gateway Adress :</td>
   <td><input type=text name=gate-addr id=4 size="3"></td>
   <td>.<input type=text name=gate-addr id=41 size="3"></td>
   <td>.<input type=text name=gate-addr id=42 size="3"></td>
   <td>.<input type=text name=gate-addr id=43 size="3"></td>
   <td></td>
  <td></td>
 <td> <input type=submit value=Apply/change></td>
   </tr>
  <tr>
   <td>Subnet Mask :</td>
   <td><input type=text name=sub-msk id=5 size="3"></td>
   <td>.<input type=text name=sub-msk id=51 size="3"></td>
   <td>.<input type=text name=sub-msk id=52 size="3"></td>
   <td>.<input type=text name=sub-msk id=53 size="3"></td>
   <td></td>
    <td></td>
     <td> <input type=submit value=Apply/change></td>
   </tr>
  <tr>
    <td>Ntp Server IP :</td>
  <td><input type=text name=ntp-ip id=6  size="3"></td>
  <td>.<input type=text name=ntp-ip id=61 size="3"></td>
  <td>.<input type=text name=ntp-ip id=62 size="3"></td>
  <td>.<input type=text name=ntp-ip id=63 size="3"></td>
  <td></td>
  <td></td>
  <td> <input type=submit value=Apply/change></td>
    </tr>
</table>
<input type=submit action=http://192.168.1.250  value=Apply/Reboot>
</form>
</body>
4

1 回答 1

0

仅发送给定块中的数据的一种方法是将每个块分成其自己的 html 表单,以便提交按钮仅提交与该块相关的值。这里的缺点是您将无法使用整体提交按钮一次提交整个表单。

另一种方法是让每个块提交按钮触发一个 javascript 函数,该函数仅发送与块相关的数据。这可以通过 Ajax 请求来完成,或者通过重定向和传递您要重定向到的位置的查询字符串中的相关值来完成。这很可能通过设置一个 javascript 函数来处理,然后通过 jQuery 的.click()功能、通过document.getElementById("buttonId").Click或通过向按钮添加onclick="relevantFunction();return false;"属性将其分配给按钮来完成。

请注意,如果您采用每个块的路线,您将需要将提交按钮切换为按钮类型而不是提交类型,或者您需要使用它return false;来阻止它们提交整个表单。有关执行此操作的示例,请参见此答案

onclick这是通过第一个块的实现使用该方法的示例。在您的 javascript 中:

function SingleSectionSubmit(inputIds, name, targetUrl)
{ //inputIds needs to be an array of the IDs for the section
   var querystring = "";

   //build requestParameter value; since each block is only one type of input, we can combine these together as long as your processing page supports that (and if it doesn't you will need to customize)
   var requestParam = "";
   for (var i = 0; i < inputIds.length; i++)
   { requestParam = requestParam + inputIds[i] + "."; }
   requestParam = requestParam.substring(0, requestParam.length - 1); //get rid of the trailing period

   querystring = "?" + name + "=" + requestParam;

   //perform the redirect
   window.location(targetUrl + querystring);
}

然后在 html 中,您可以将相关按钮设置为:

<input type="submit" value="Apply/change" onclick="SingleSectionSubmit(['1','11'], 'dev-info', 'http://192.168.1.250');">

同样,这假设您提交到的页面(http://192.168.1.250在这种情况下)能够使用来自查询字符串的 GET 变量来处理请求。

于 2013-04-15T13:28:56.697 回答