...

View Full Version : checkbox checked on default



yasmeencarter
10-18-2003, 08:41 PM
I need to have "Chk1" checkbox check the first time the person logs in the page, and the rest is either checkbox 1 or 2 just like I have.. This is for a search textbox , which you could search by lastname or firstname.
. The only problem is to have checkbox 1 checked the first time,, could someone help with that. thanks


<SCRIPT LANGUAGE="JavaScript">
function setChecked(checkName)
{
var doc = document.Compaq;
if (checkName == "chk1")
{
doc.Chk2.checked = 0;
}
else
if (checkName == "chk2")
{
doc.Chk1.checked = 0;
}

}
</SCRIPT>

<FORM METHOD="POST" ACTION="test.cfm" NAME="Compaq">
<INPUT TYPE="CHECKBOX" NAME="Chk1" VALUE="1" ONCLICK="setChecked('chk1')">Check 1

<INPUT TYPE="CHECKBOX" NAME="Chk2" VALUE="2" ONCLICK="setChecked('chk2')">Check 2

</FORM>

Willy Duitt
10-18-2003, 09:59 PM
<INPUT TYPE="CHECKBOX" NAME="Chk1" VALUE="1" ONCLICK="setChecked('chk1')" checked>Check 1

....Willy

missing-score
10-18-2003, 10:12 PM
are you saying that you want to force the user to choose one or the other? i think willy got it right, but im not sure.

Also, for the checkbox, you should use:

<input type="checkbox" checked="checked" ... />

Mr J
10-18-2003, 10:16 PM
Loke this maybe?


<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function init(){
document.Compaq.Chk1.checked=true
document.Compaq.Chk2.checked=false
}
function setChecked(checkName){
var doc = document.Compaq;
if (checkName == "chk1"){
doc.Chk2.checked = 0;
}
else
if (checkName == "chk2"){
doc.Chk1.checked = 0;
}
}
</SCRIPT>
</HEAD>
<BODY onload="init()">
<FORM METHOD="POST" ACTION="test.cfm" NAME="Compaq">
<INPUT TYPE="CHECKBOX" NAME="Chk1" VALUE="1" ONCLICK="setChecked('chk1')">Check 1
<INPUT TYPE="CHECKBOX" NAME="Chk2" VALUE="2" ONCLICK="setChecked('chk2')">Check 2
</FORM>
</BODY>
</HTML>

yasmeencarter
10-19-2003, 01:56 AM
Thank you to all of you. This is what I was looking for. thanks again


<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function init(){
document.Compaq.Chk1.checked=true
document.Compaq.Chk2.checked=false
}
function setChecked(checkName){
var doc = document.Compaq;
if (checkName == "chk1"){
doc.Chk2.checked = 0;
}
else
if (checkName == "chk2"){
doc.Chk1.checked = 0;
}
}
</SCRIPT>
</HEAD>
<BODY onload="init()">
<FORM METHOD="POST" ACTION="test.cfm" NAME="Compaq">
<INPUT TYPE="CHECKBOX" NAME="Chk1" VALUE="1" ONCLICK="setChecked('chk1')">Check 1
<INPUT TYPE="CHECKBOX" NAME="Chk2" VALUE="2" ONCLICK="setChecked('chk2')">Check 2
</FORM>
</BODY>
</HTML>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum