2011-09-05 83 views
0

我有以下形式:複選框選中值去文本框(切換等)

<form action="" method="get"> 
<input name="form1" type="radio" onclick="document.forms[0].testbox.value='0.00'; "/> 
<input name="form1" type="radio" onclick="document.forms[0].testbox.value='1.00'; "/> 
<input name="" type="checkbox" value="" onclick="document.forms[0].testbox2.value='1.00'; "/> 
<input name="testbox" type="text" value="0.00"/> 
<input name="testbox2" type="text" value="0.00"/> 
</form> 

當單選按鈕改變,在文本框中的值也會發生變化,從0.00到1.00回到1.00等。

我想要做的週期/複選框同樣的事情 - 當點擊了testbox2價值應該成爲1.00,當未點擊應該回到0.00 ..

同樣的onclick編碼不工作?想法?

謝謝

發表意見之後試過這種..但是不工作?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 
<script type="text/javascript"> 
function checkboxClick() { 
var textbox = document.forms[0].testbox2; 
textbox.value = (textbox.value == 0) ? '1.00' : '0.00'; 
} 
</script> 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
</head> 
<form action="" method="get"> 
<input name="form1" type="radio" onclick="document.forms[0].testbox.value='0.00'; "/> 
<input name="form1" type="radio" onclick="document.forms[0].testbox.value='1.00'; "/> 
<input name="" type="checkbox" value="" onclick="document.forms[0].testbox2.value='1.00'; "/> 
<input name="testbox" type="text" /> 
<input name="testbox2" type="text" value="0.00"/> 
</form> 
<body> 
</body> 
</html> 

忘了補充這一變化的onclick的建議如下變化..謝謝你..完美..

+1

java?你的意思是JavaScript? –

+0

對不起.. ..會改變..謝謝.. – user718359

+0

canadiancreed剛換了我..謝謝.. – user718359

回答

0

你需要切換值0和1之間你的onclick僅設置文本框爲1.00。

<script> 
function checkboxClick() { 
    var textbox = document.forms[0].testbox2; 
    textbox.value = (textbox.value == 0) ? '1.00' : '0.00'; 
} 
</script> 

<form method='get' action='#'> 
    <input name='testbox2' value='0.00'> 
    <input type='checkbox' onclick='checkboxClick()'> 
</form> 
+0

謝謝...完美.. – user718359