添加额外数值以形成单选按钮。

huangapple go评论102阅读模式
英文:

Including additonal values to form radio buttons

问题

我有一个表单,里面有3个单选按钮。第一个按钮按预期工作,但接下来的两个按钮有额外的值。如果可能的话,当选择单选按钮Choice2或Choice3时,如何包含额外的值?

<form>
  <fieldset>
    <legend>选择报告范围:</legend>
    <div>
      <input type="radio" id="Choice1" name="contactRange" value="lastReport"/>
      <label for="Choice1">上次报告</label><br>

      <input type="radio" id="Choice2" name="contactRange" value="numOfDays"/>
      <label>过去的报告 </label>
        <select>
          <option value="1"> 1 天</option>
          <option value="2"> 2 天</option>
          <option value="3"> 3 天</option>
          <option value="4"> 4 天</option>
          <option value="5"> 5 天</option>
        </select>
      <br>

      <input type="radio" id="Choice3" name="contactRange" value="dateRange">
      <label for="Choice3">日期范围</label>
        <input type="text1" name="startDate" placeholder="开始日期(最旧)">
        <input type="text2" name="endDate"   placeholder="结束日期(最近)">
    </div>

    <div>
      <br><button type="submit">提交</button><br>
    </div>
  </fieldset>
</form>
英文:

I have a form with 3 radio buttons. The first button works as expected, but the next two have additional values. If it is possible, how can I include the additional values when radio buttons Choice2 or Choice3 are selected?

&lt;form&gt;
  &lt;fieldset&gt;
    &lt;legend&gt;Select Report Range:&lt;/legend&gt;
    &lt;div&gt;
      &lt;input type=&quot;radio&quot; id =&quot;Choice1&quot; name=&quot;contactRange&quot; value=&quot;lastReport&quot;/&gt;
      &lt;label for=&quot;Choice1&quot;&gt;Last report&lt;/label&gt;&lt;br&gt;

      &lt;input type=&quot;radio&quot; id=&quot;Choice2&quot; name=&quot;contactRange&quot; value=&quot;numOfDays&quot;/&gt;
      &lt;label&gt;Reports for the last &lt;/label&gt;
        &lt;select&gt;
          &lt;option value=&quot;1&quot;&gt; 1 day&lt;/option&gt;
          &lt;option value=&quot;2&quot;&gt; 2 days&lt;/option&gt;
          &lt;option value=&quot;3&quot;&gt; 3 days&lt;/option&gt;
          &lt;option value=&quot;4&quot;&gt; 4 days&lt;/option&gt;
          &lt;option value=&quot;5&quot;&gt; 5 days&lt;/option&gt;
        &lt;/select&gt;
      &lt;br&gt;

      &lt;input type=&quot;radio&quot; id=&quot;Choice3&quot; name=&quot;contactRange&quot; value=&quot;dateRange&quot;&gt;
      &lt;label for=&quot;Choice3&quot;&gt;Date Range&lt;/label&gt;
        &lt;input type=&quot;text1&quot; name=&quot;startDate&quot; placeholder=&quot;Start Date (oldest)&quot;&gt;
        &lt;input type=&quot;text2&quot; name=&quot;endDate&quot;   placeholder=&quot;End Date (most recent)&quot;&gt;
    &lt;/div&gt;

    &lt;div&gt;
      &lt;br&gt;&lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;&lt;br&gt;
    &lt;/div&gt;
  &lt;/fieldset&gt;
&lt;/form&gt;

I tried adding value= to each of the option and text selections without success. I also tried adding a form within a form but that got pretty ugly and also did not work.

答案1

得分: 0

成功!!!(有点丑,但它有效。)

<form>
  <fieldset>
    <legend>选择报告范围:</legend>

      <input type="radio" id="Choice1" name="contactRange" value="lastReport">
      <label for="Choice1">上次报告</label><br>

      <input type="radio" id="Choice2" name="contactRange" value="numOfDays">
      <label>最近报告</label>
        <select name="days" id="number">
          <option value="1">1 天</option>
          <option value="2">2 天</option>
          <option value="3">3 天</option>
          <option value="4">4 天</option>
          <option value="5">5 天</option>
        </select>
      <br>

      <input type="radio" id="Choice3" name="contactRange" value="dateRange">
      <label for="Choice3">日期范围</label>
        <input type="text1" name="startDate" placeholder="开始日期(最旧)">
        <input type="text2" name="endDate" placeholder="结束日期(最新)">

    <div>
      <br><button type="submit">提交</button><br>
    </div>
  </fieldset>
</form>

第一种情况 "上次报告":
contactRange=lastReport&days=1&startDate=&endDate=

第二种情况 "最近" 2 天的报告:
contactRange=numOfDays&days=2&startDate=&endDate=

第三种情况 "日期范围" 10/3/2023 4:30 AM 到 11/2/2023 6:30 PM:
days=1&contactRange=dateRange&startDate=10%2F3%2F2023+4%3A30+AM&endDate=11%2F2%2F2023+6%3A30+PM

服务器将接受表单输出并解析正确的 "contactRange=" 数据。其余数据只是噪音。

英文:

Sucess!!! (Kind of... the output is ugly but it works.)

&lt;form&gt;
  &lt;fieldset&gt;
    &lt;legend&gt;Select Report Range:&lt;/legend&gt;

      &lt;input type=&quot;radio&quot; id =&quot;Choice1&quot; name=&quot;contactRange&quot; value=&quot;lastReport&quot;&gt;
      &lt;label for=&quot;Choice1&quot;&gt;Last report&lt;/label&gt;&lt;br&gt;

      &lt;input type=&quot;radio&quot; id=&quot;Choice2&quot; name=&quot;contactRange&quot; value=&quot;numOfDays&quot;&gt;
      &lt;label&gt;Reports for the last &lt;/label&gt;
        &lt;select name=&quot;days&quot; id=&quot;number&quot;&gt;
          &lt;option value=&quot;1&quot;&gt; 1 day&lt;/option&gt;
          &lt;option value=&quot;2&quot;&gt; 2 days&lt;/option&gt;
          &lt;option value=&quot;3&quot;&gt; 3 days&lt;/option&gt;
          &lt;option value=&quot;4&quot;&gt; 4 days&lt;/option&gt;
          &lt;option value=&quot;5&quot;&gt; 5 days&lt;/option&gt;
        &lt;/select&gt;
      &lt;br&gt;

      &lt;input type=&quot;radio&quot; id=&quot;Choice3&quot; name=&quot;contactRange&quot; value=&quot;dateRange&quot;&gt;
      &lt;label for=&quot;Choice3&quot;&gt;Date Range&lt;/label&gt;
        &lt;input type=&quot;text1&quot; name=&quot;startDate&quot; placeholder=&quot;Start Date (oldest)&quot;&gt;
        &lt;input type=&quot;text2&quot; name=&quot;endDate&quot;   placeholder=&quot;End Date (most recent)&quot; &gt;

    &lt;div&gt;
      &lt;br&gt;&lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;&lt;br&gt;
    &lt;/div&gt;
  &lt;/fieldset&gt;
&lt;/form&gt;

First case "Last report":
contactRange=lastReport&days=1&startDate=&endDate=

Second case "Reports for the last" 2 days:
contactRange=numOfDays&days=2&startDate=&endDate=

Third case "Date Range" 10/3/2023 4:30 AM 11/2/2023 6:30 PM:
days=1&contactRange=dateRange&startDate=10%2F3%2F2023+4%3A30+AM&endDate=11%2F2%2F2023+6%3A30+PM

The server will take the form output and parse the data for the correct "contactRange=". The rest of the data is just noise.

huangapple
  • 本文由 发表于 2023年3月10日 01:00:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75687759.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定