我在我的表單中有一個性別字段。使用javascript提交表單?
我已經給它相同的名稱,即「社會性別」,我給它相同的ID,即「社會性別」。
現在我要展示我選擇了這兩個選項。但是,使用相同的ID,它不起作用。我已將onclick事件應用於文本框,並且我希望它能夠在每次點擊該文本框時都顯示一條javascript警報,顯示我已選擇的內容,無論是男性還是女性。
請幫忙!
gender:<input type="radio" name="gender" id="gender" value="female"/>female
:<input type="radio" name="gender" id="gender" value="male" />male
<input type="text" name="textbox" onclick="check()" />
<script type="text/javascript">
function check()
{
var a=document.getElementById("gender").value;
alert(a);
}
</script>
function addUser() {
//how to check what is the selected radio input
alert(getCheckedRadioId('u_type'));
}
function getCheckedRadioId(name) {
var elements = document.getElementsByName(name);
for (var i=0, len=elements.length; i<len; ++i)
if (elements[i].checked) return elements[i].value;
}
</script>
now this code alerts that what i have choosen but the problem is that i want the alert's value in a variable so that i could send this value to database...so how should i take the alerted value in a variable.....
WElcome to SO。下次,請結束你的句子,只有1。 ,而不是3或4.請記住試着寫下你的問題,以便讓這裏的人們更容易地深入你的問題! –