2016-08-23 173 views
0
Activity Level<br> 
     <input type = "radio" id="activitylevel" value="sedentary">Sedentary - Little or no exercise, desk job</option><br> 
     <input type = "radio" id="activitylevel" value="lightly">Lightly active - Light exercise or sports 1-3 days/wk</option><br> 
     <input type = "radio" id="activitylevel" value="moderately">Moderately active Moderate exercise or sports 3-5 days/wk</option><br> 
     <input type = "radio" id="activitylevel" value="very">Very active - Hard exercise or sports 6-7 days/wk</option><br> 
     <input type = "radio" id="activitylevel" value="extremely">Extremely Active - Hard daily exercise or sports & physical labor job or 2 X day training, football camp, etc.</option><br> 

這是否有問題?我花了一個小時看看我的代碼的其餘部分,弄清楚爲什麼我無法將這些值發送到這個表單上,我開始認爲這個代碼有問題。有任何想法嗎?我在網上看過例子,他們不使用'id'?HTML單選按鈕

謝謝,一個非常noobie的問題,但任何指針或幫助表示讚賞。

+0

您是如何得到這些值的? –

+0

用名稱替換ID –

回答

0

必須爲單選按鈕

定義名稱這樣

<input type = "radio" id="activitylevel" name="activitylevel" value="sedentary"> 
+0

非常感謝。 – PMG

+0

如果這個答案是正確的,請接受這個答案 – ashkufaraz

1

我想,你忘了寫名字)名稱必須相同,例如name="radio_name"所有無線輸入。寫如下。但是html中的id一定不能相同。爲什麼你使用我無法理解。

<input type="radio" name="activitylevel" id="activitylevel_1" value="sedentary">Sedentary - Little or no exercise, desk job<br> 
<input type = "radio" name="activitylevel" id="activitylevel_2" value="lightly">Lightly active - Light exercise or sports 1-3 days/wk<br> 
<input type = "radio" name="activitylevel" id="activitylevel_3" value="moderately">Moderately active Moderate exercise or sports 3-5 days/wk<br> 
<input type = "radio" name="activitylevel" id="activitylevel_4" value="very">Very active - Hard exercise or sports 6-7 days/wk<br> 
<input type = "radio" name="activitylevel" id="activitylevel_5" value="extremely">Extremely Active - Hard daily exercise or sports & physical labor job or 2 X day training, football camp, etc.<br> 
0

您需要設置每個輸入字段名稱,然後在嘗試檢索值時引用該名稱。例如:

<input type = "radio" name="activitylevel">Sedentary - Little or no exercise, desk job</option><br>

0

輸入不提交表單時名稱將不會被提交。所以你需要爲你的輸入添加名字。也似乎有一些語法錯誤。更正後的代碼如下所示:`

<input type = "radio" id="activitylevel1" value="sedentary" name="activitylevel">Sedentary - Little or no exercise, desk job</input> 
     <input type = "radio" id="activitylevel2" value="lightly" name="activitylevel">Lightly active - Light exercise or sports 1-3 days/wk</input> 
     <input type = "radio" id="activitylevel3" value="moderately" name="activitylevel">Moderately active Moderate exercise or sports 3-5 days/wk</input> 
     <input type = "radio" id="activitylevel4" value="very" name="activitylevel">Very active - Hard exercise or sports 6-7 days/wk</input> 
     <input type = "radio" id="activitylevel5" value="extremely" name="activitylevel">Extremely Active - Hard daily exercise or sports & physical labor job or 2 X day training, football camp, etc.</input>`