getElementById を使用する代わりに getElementByValue を使用したいオプション選択を検出するのに問題があります。存在しますか?? これは私のコードです
<script type="text/javascript">
var total;
function oneway(){
document.getElementById("return_date").style.visibility = "hidden";
document.getElementById("return_time").style.visibility = "hidden";
}
function return_way(){
document.getElementById("return_date").style.visibility = "visible";
document.getElementById("return_time").style.visibility = "visible";
}
function state_price(){
var way=document.getElementById("direction").value;
var placefrom = document.getElementById("state_from").value;
var placeto = document.getElementById("state_to").value;
if (direction == "oneway"){
if ((placefrom=="Batu Pahat" && placeto=="Alor Setar") ||(placefrom =="Alor Setar" && placeto=="Batu Pahat")){
total=55.00;
document.booking.total_price.value = total;
}else if ((placefrom=="Batu Pahat" && placeto=="Bachok")||(placefrom=="Bachok" && placeto=="Batu Pahat"))
{
total=60.00;
document.booking.total_price.value = total;
}else if ((placefrom=="Batu Pahat" && placeto=="A Famosa") || (placefrom=="A Famosa" && placeto=="Batu Pahat"))
{
total=65.50;
document.booking.total_price.value = total;
}else if ((placefrom=="Batu Pahat" && placeto=="Bahau")||(placefrom=="Bahau" && placeto=="Batu Pahat"))
{
total=70.00;
document.booking.total_price.value = total;
}else if ((placefrom=="Batu Pahat" && placeto=="Bentong") ||(placefrom=="Bentong" && placeto=="Batu Pahat"))
{
total=75.50;
document.booking.total_price.value = total;
}else if ((placefrom=="Batu Pahat" && placeto=="Kubang Kerian") ||(placefrom=="Kubang Kerian" && placeto=="Batu Pahat"))
{
total=80.00;
document.booking.total_price.value = total;
}
else
{
document.booking.txttotal.value = "Fail";
window.alert("Please enter a different destination");
}
}
else
{
///something else
}
}
</script>
これは私のHTMLコーディングの一部です
<tr >
<td>Travel Direction:</td>
<td >
<input type="radio" name ="direction" value = "oneway" onclick = "oneway()"/>One Way
<input type="radio" name ="direction" value = "return" onclick = "return_way()"/>Return
</td>
</tr>
PHPコーディングで使用しているので、名前を使用したくないので、使用したくありません.上記のようにjavascriptを実行できる方法はありますか(getElementByValue)?ありがとうあらかじめ