英文:
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?
<form>
<fieldset>
<legend>Select Report Range:</legend>
<div>
<input type="radio" id ="Choice1" name="contactRange" value="lastReport"/>
<label for="Choice1">Last report</label><br>
<input type="radio" id="Choice2" name="contactRange" value="numOfDays"/>
<label>Reports for the last </label>
<select>
<option value="1"> 1 day</option>
<option value="2"> 2 days</option>
<option value="3"> 3 days</option>
<option value="4"> 4 days</option>
<option value="5"> 5 days</option>
</select>
<br>
<input type="radio" id="Choice3" name="contactRange" value="dateRange">
<label for="Choice3">Date Range</label>
<input type="text1" name="startDate" placeholder="Start Date (oldest)">
<input type="text2" name="endDate" placeholder="End Date (most recent)">
</div>
<div>
<br><button type="submit">Submit</button><br>
</div>
</fieldset>
</form>
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.)
<form>
<fieldset>
<legend>Select Report Range:</legend>
<input type="radio" id ="Choice1" name="contactRange" value="lastReport">
<label for="Choice1">Last report</label><br>
<input type="radio" id="Choice2" name="contactRange" value="numOfDays">
<label>Reports for the last </label>
<select name="days" id="number">
<option value="1"> 1 day</option>
<option value="2"> 2 days</option>
<option value="3"> 3 days</option>
<option value="4"> 4 days</option>
<option value="5"> 5 days</option>
</select>
<br>
<input type="radio" id="Choice3" name="contactRange" value="dateRange">
<label for="Choice3">Date Range</label>
<input type="text1" name="startDate" placeholder="Start Date (oldest)">
<input type="text2" name="endDate" placeholder="End Date (most recent)" >
<div>
<br><button type="submit">Submit</button><br>
</div>
</fieldset>
</form>
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论