tooki
asked on
Javascript checkbox
In my HTML form page I have a textfield and a checkbox.
I want user not to be able to write inside the text field before he/she checks the checkbox (that means by default the checkbox will be unchecked and by default the textfield is not writeable). After user checks the checkbox, user can type in the textfield. How can we do it. ..pls help.
Here is my code:
***abc.html***
<html>
<head>
<script language="JavaScript">
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="test" method="post" action="menu.jsp?option=2. 1.4">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<input type=checkbox><input type="text" name="C_13" size="45" maxlength="128">
</td>
</tr>
</table>
</form>
</body>
</html>
***abc.html***
I want user not to be able to write inside the text field before he/she checks the checkbox (that means by default the checkbox will be unchecked and by default the textfield is not writeable). After user checks the checkbox, user can type in the textfield. How can we do it. ..pls help.
Here is my code:
***abc.html***
<html>
<head>
<script language="JavaScript">
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="test" method="post" action="menu.jsp?option=2.
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<input type=checkbox><input type="text" name="C_13" size="45" maxlength="128">
</td>
</tr>
</table>
</form>
</body>
</html>
***abc.html***
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
o00ps I guess we Submited at the Same Time, Guy you won the Auction:) hehehehe LOL
Yep close one, I usually loose out on this I got there first for once. :-)
ASKER
You guys are great!!
Hey..sorry actually I still have problem..actually in my page I have :
1 checkbox, 2 textfield and 1 selectfield.
When I choose one item in the selectfield, it populates the textfields (both) with some logic.
What I need is:
if checkbox is deselected:
"none of the textfields shall be writable", also even if we select any item in the selectfield, it will not populate any of the textfields!
if checkbox is selected:
both the textfield shall be writable and I should be able to populate the textfields by choosing items in the selectfield.
Is it possible?
Here is the code:
***abc2.html***
<html>
<head>
<title>FASTT</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="fastt.css" type="text/css">
<script language="JavaScript">
<!-- Hide script from older browsers
function fillInputValue(select_box, component_id) {
var user_choice = select_box.options[select_ box.select edIndex].v alue
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu m+1, user_choice.length)
}
eval("document.forms[0].C_ " + component_id + ".value = \"" + user_choice1 + "\"")
eval("document.forms[0].V_ " + component_id + ".value = \"" + user_choice2 + "\"")
}
function setSelectValue(select_box, component_id) {
var user_choice = select_box.options[select_ box.select edIndex].v alue
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu m+1, user_choice.length)
}
var target_select = eval("document.forms[0].C_ " + component_id)
for (var i = 0; i < target_select.length; i++) {
if (target_select.options[i]. value == user_choice1) {
target_select.options[i].s elected = true
eval("document.forms[0].V_ " + component_id + ".value = \"" + user_choice2 + "\"")
break
}
}
}
// End hiding script -->
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="model_config_create" method="post" action="menu.jsp?option=2. 1.4">
<tr>
<td class="content_field_label " valign="top" width="100"><input type="checkbox" name="R_31" value="ON" onClick="(this.checked)?C_ 31.disable d=false:C_ 31.disable d=true"></ td>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<input type="text" name="C_31" size="45" maxlength="128" disabled>
<b>Version:</b ><input type="text" name="V_31" size="25" maxlength="128">
<input type="hidden" name="w_components" value="8|DCComp3|C_31">
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" class="content_field_label ">Candidat e #1:</td>
<td>
<select name="select_31_1" onChange="fillInputValue(t his, 31)">
<option value="">(Choose One)</option>
<option value="HE:V">HE:V</option>
<option value="HEHE:HE_V">HE:HE_V< /option>
<option value="HI124:HI124_V">HI12 4:HI124_V< /option>
</select>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
***abc2.html***
thanks!
-tooki
Hey..sorry actually I still have problem..actually in my page I have :
1 checkbox, 2 textfield and 1 selectfield.
When I choose one item in the selectfield, it populates the textfields (both) with some logic.
What I need is:
if checkbox is deselected:
"none of the textfields shall be writable", also even if we select any item in the selectfield, it will not populate any of the textfields!
if checkbox is selected:
both the textfield shall be writable and I should be able to populate the textfields by choosing items in the selectfield.
Is it possible?
Here is the code:
***abc2.html***
<html>
<head>
<title>FASTT</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="fastt.css" type="text/css">
<script language="JavaScript">
<!-- Hide script from older browsers
function fillInputValue(select_box,
var user_choice = select_box.options[select_
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu
}
eval("document.forms[0].C_
eval("document.forms[0].V_
}
function setSelectValue(select_box,
var user_choice = select_box.options[select_
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu
}
var target_select = eval("document.forms[0].C_
for (var i = 0; i < target_select.length; i++) {
if (target_select.options[i].
target_select.options[i].s
eval("document.forms[0].V_
break
}
}
}
// End hiding script -->
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="model_config_create"
<tr>
<td class="content_field_label
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<input type="text" name="C_31" size="45" maxlength="128" disabled>
<b>Version:</b
<input type="hidden" name="w_components" value="8|DCComp3|C_31">
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" class="content_field_label
<td>
<select name="select_31_1" onChange="fillInputValue(t
<option value="">(Choose One)</option>
<option value="HE:V">HE:V</option>
<option value="HEHE:HE_V">HE:HE_V<
<option value="HI124:HI124_V">HI12
</select>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
***abc2.html***
thanks!
-tooki
<html>
<head>
<title>FASTT</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="fastt.css" type="text/css">
<script language="JavaScript">
<!-- Hide script from older browsers
function fillInputValue(select_box, component_id) {
var user_choice = select_box.options[select_ box.select edIndex].v alue
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu m+1, user_choice.length)
}
eval("document.forms[0].C_ " + component_id + ".value = \"" + user_choice1 + "\"")
eval("document.forms[0].V_ " + component_id + ".value = \"" + user_choice2 + "\"")
}
function setSelectValue(select_box, component_id) {
var user_choice = select_box.options[select_ box.select edIndex].v alue
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu m+1, user_choice.length)
}
var target_select = eval("document.forms[0].C_ " + component_id)
for (var i = 0; i < target_select.length; i++) {
if (target_select.options[i]. value == user_choice1) {
target_select.options[i].s elected = true
eval("document.forms[0].V_ " + component_id + ".value = \"" + user_choice2 + "\"")
break
}
}
}
// End hiding script -->
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="model_config_create" method="post" action="menu.jsp?option=2. 1.4">
<tr>
<td class="content_field_label " valign="top" width="100"><input type="checkbox" name="R_31" value="ON" onClick="if(this.checked){ C_31.disab led=false; select_31_ 1.disabled =false;V_3 1.disabled =false;} else {C_31.disabled=true;select _31_1.disa bled=true; V_31.disab led=true;} "></td>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<input type="text" name="C_31" size="45" maxlength="128" disabled>
<b>Version:</b ><input type="text" name="V_31" size="25" maxlength="128" disabled>
<input type="hidden" name="w_components" value="8|DCComp3|C_31">
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" class="content_field_label ">Candidat e #1:</td>
<td>
<select name="select_31_1" onChange="fillInputValue(t his, 31)" disabled>
<option value="">(Choose One)</option>
<option value="HE:V">HE:V</option>
<option value="HEHE:HE_V">HE:HE_V< /option>
<option value="HI124:HI124_V">HI12 4:HI124_V< /option>
</select>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<head>
<title>FASTT</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="fastt.css" type="text/css">
<script language="JavaScript">
<!-- Hide script from older browsers
function fillInputValue(select_box,
var user_choice = select_box.options[select_
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu
}
eval("document.forms[0].C_
eval("document.forms[0].V_
}
function setSelectValue(select_box,
var user_choice = select_box.options[select_
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu
}
var target_select = eval("document.forms[0].C_
for (var i = 0; i < target_select.length; i++) {
if (target_select.options[i].
target_select.options[i].s
eval("document.forms[0].V_
break
}
}
}
// End hiding script -->
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="model_config_create"
<tr>
<td class="content_field_label
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<input type="text" name="C_31" size="45" maxlength="128" disabled>
<b>Version:</b
<input type="hidden" name="w_components" value="8|DCComp3|C_31">
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" class="content_field_label
<td>
<select name="select_31_1" onChange="fillInputValue(t
<option value="">(Choose One)</option>
<option value="HE:V">HE:V</option>
<option value="HEHE:HE_V">HE:HE_V<
<option value="HI124:HI124_V">HI12
</select>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You did not defined the Select name in the if statement.
<html>
<head>
<title>FASTT</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="fastt.css" type="text/css">
<script language="JavaScript">
<!-- Hide script from older browsers
function fillInputValue(select_box, component_id) {
var user_choice = select_box.options[select_ box.select edIndex].v alue
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu m+1, user_choice.length)
}
eval("document.forms[0].C_ " + component_id + ".value = \"" + user_choice1 + "\"")
eval("document.forms[0].V_ " + component_id + ".value = \"" + user_choice2 + "\"")
}
function setSelectValue(select_box, component_id) {
var user_choice = select_box.options[select_ box.select edIndex].v alue
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu m+1, user_choice.length)
}
var target_select = eval("document.forms[0].C_ " + component_id)
for (var i = 0; i < target_select.length; i++) {
if (target_select.options[i]. value == user_choice1) {
target_select.options[i].s elected = true
eval("document.forms[0].V_ " + component_id + ".value = \"" + user_choice2 + "\"")
break
}
}
}
// End hiding script -->
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="model_config_create" method="post" action="menu.jsp?option=2. 1.4">
<tr>
<td class="content_field_label " valign="top" width="100"><input type="checkbox" name="R_31" value="ON" onClick="if(this.checked){ C_31.disab led = false; V_31.disabled = false;select_31_1.disabled =false;} else {C_31.disabled=true; V_31.disabled= true;select_31_1.disabled= true;}"></ td>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<input type="text" name="C_31" size="45" maxlength="128" disabled>
<b>Version:</b ><input type="text" name="V_31" size="25" maxlength="128" disabled>
<input type="hidden" name="w_components" value="8|DCComp3|C_31">
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" class="content_field_label ">Candidat e #1:</td>
<td>
<select name="select_31_1" onChange="if(!R_31.checked ) return false; else fillInputValue(this, 31)">
<option value="">(Choose One)</option>
<option value="HE:V">HE:V</option>
<option value="HEHE:HE_V">HE:HE_V< /option>
<option value="HI124:HI124_V">HI12 4:HI124_V< /option>
</select>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<html>
<head>
<title>FASTT</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="fastt.css" type="text/css">
<script language="JavaScript">
<!-- Hide script from older browsers
function fillInputValue(select_box,
var user_choice = select_box.options[select_
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu
}
eval("document.forms[0].C_
eval("document.forms[0].V_
}
function setSelectValue(select_box,
var user_choice = select_box.options[select_
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu
}
var target_select = eval("document.forms[0].C_
for (var i = 0; i < target_select.length; i++) {
if (target_select.options[i].
target_select.options[i].s
eval("document.forms[0].V_
break
}
}
}
// End hiding script -->
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="model_config_create"
<tr>
<td class="content_field_label
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<input type="text" name="C_31" size="45" maxlength="128" disabled>
<b>Version:</b
<input type="hidden" name="w_components" value="8|DCComp3|C_31">
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" class="content_field_label
<td>
<select name="select_31_1" onChange="if(!R_31.checked
<option value="">(Choose One)</option>
<option value="HE:V">HE:V</option>
<option value="HEHE:HE_V">HE:HE_V<
<option value="HI124:HI124_V">HI12
</select>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
To clear things up, the difference between my code and adilkhan's code is that my code allows you to use the select box, but it won't write to the text fields unless checked while adilkhan's disables the select box along with the text fields. Not sure which one you're looking for.
Tooki, I come back to see how th equestion is going , I thought I ahd answered it now I find the has changed. This is my version, clicking the check box flips the disabled property for the field starting with all disabled. (ie !true=false and !false=true)
<html>
<head>
<title>FASTT</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="fastt.css" type="text/css">
<script language="JavaScript">
<!-- Hide script from older browsers
function fillInputValue(select_box, component_id) {
var user_choice = select_box.options[select_ box.select edIndex].v alue
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu m+1, user_choice.length)
}
eval("document.forms[0].C_ " + component_id + ".value = \"" + user_choice1 + "\"")
eval("document.forms[0].V_ " + component_id + ".value = \"" + user_choice2 + "\"")
}
function setSelectValue(select_box, component_id) {
var user_choice = select_box.options[select_ box.select edIndex].v alue
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu m+1, user_choice.length)
}
var target_select = eval("document.forms[0].C_ " + component_id)
for (var i = 0; i < target_select.length; i++) {
if (target_select.options[i]. value == user_choice1) {
target_select.options[i].s elected = true
eval("document.forms[0].V_ " + component_id + ".value = \"" + user_choice2 + "\"")
break
}
}
}
// End hiding script -->
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="model_config_create" method="post" action="menu.jsp?option=2. 1.4">
<input type="hidden" name="w_components" value="8|DCComp3|C_31"><ta ble>
<tr>
<td class="content_field_label " valign="top" width="100"><input type="checkbox"
name="R_31" value="ON"
onClick="C_31.disabled=!C_ 31.disable d;V_31.dis abled=!V_3 1.disabled ;select_31 _1.disable d=!select_ 31_1.disab led"></td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="text" name="C_31" size="45" maxlength="128" disabled> <b>Version:</b >
<input type="text" name="V_31" size="25" maxlength="128" disabled> </td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" class="content_field_label ">Candidat e #1:</td>
<td><select name="select_31_1" onChange="fillInputValue(t his, 31)" size="1" disabled>
<option value>(Choose One)</option>
<option value="HE:V">HE:V</option>
<option value="HEHE:HE_V">HE:HE_V< /option>
<option value="HI124:HI124_V">HI12 4:HI124_V< /option>
</select> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<html>
<head>
<title>FASTT</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="fastt.css" type="text/css">
<script language="JavaScript">
<!-- Hide script from older browsers
function fillInputValue(select_box,
var user_choice = select_box.options[select_
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu
}
eval("document.forms[0].C_
eval("document.forms[0].V_
}
function setSelectValue(select_box,
var user_choice = select_box.options[select_
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu
}
var target_select = eval("document.forms[0].C_
for (var i = 0; i < target_select.length; i++) {
if (target_select.options[i].
target_select.options[i].s
eval("document.forms[0].V_
break
}
}
}
// End hiding script -->
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="model_config_create"
<input type="hidden" name="w_components" value="8|DCComp3|C_31"><ta
<tr>
<td class="content_field_label
name="R_31" value="ON"
onClick="C_31.disabled=!C_
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="text" name="C_31" size="45" maxlength="128" disabled> <b>Version:</b
<input type="text" name="V_31" size="25" maxlength="128" disabled> </td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" class="content_field_label
<td><select name="select_31_1" onChange="fillInputValue(t
<option value>(Choose One)</option>
<option value="HE:V">HE:V</option>
<option value="HEHE:HE_V">HE:HE_V<
<option value="HI124:HI124_V">HI12
</select> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
If the option box is always to be active remove select_31_1.disabled=!sele ct_31_1.di sabled and disabled attribute from it definition.
ASKER
Thanks everyone!!Thanks a lot.Everyone's answer is acceptable to me.But there is one thing that :
after checking(selecting) the checkbox, if I type on the textfield(s) or choose an entry from the selectfield and then uncheck(deselect) the checkbox, the content of those textfield(s) remains and go through the form to the next page and I do not want that.
Is there any way that when the checkbox is deselected, the existing entries in the textfield(s) are set to null(blank)?
thanks!
-tooki
after checking(selecting) the checkbox, if I type on the textfield(s) or choose an entry from the selectfield and then uncheck(deselect) the checkbox, the content of those textfield(s) remains and go through the form to the next page and I do not want that.
Is there any way that when the checkbox is deselected, the existing entries in the textfield(s) are set to null(blank)?
thanks!
-tooki
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
simply add this line on your onClick event
onClick="document.forms['f orm_name'] .reset();a ll_other_s cripts_for _disabling _textboxes "
onClick="document.forms['f
in my code change
onClick="C_31.disabled=!C_ 31.disable d;V_31.dis abled=!V_3 1.disabled ;select_31 _1.disable d=!select_ 31_1.disab led">
to
onClick="C_13.value="";C_3 1.disabled =!C_31.dis abled;V_13 .value=""; V_31.disab led=!V_31. disabled;s elect_31_1 .disabled= !select_31 _1.disable d">
onClick="C_31.disabled=!C_
to
onClick="C_13.value="";C_3
sajuks, did'nt see your post. GfW
No problems GwynforWeb , since you hadnt replied to the post for a long time i had replied. Hope you dont mind.
If you get the points it all yours. none needed for me. ( Not expecting any for me :-) )
Regards
If you get the points it all yours. none needed for me. ( Not expecting any for me :-) )
Regards
tooki.
if you dont want the context to send to the next form simply disable the textfield/textarea
in this case it will not be submitted.
Nushi.
if you dont want the context to send to the next form simply disable the textfield/textarea
in this case it will not be submitted.
Nushi.
ASKER
Thanks much! It works but there is a problem too. After I submit (with some content in the textfields and the checkbox checked) and then if I come back to the previous page (current page that we are talking about), then the "checkbox remain checked but the textfields and the select field goes disabled!! If we uncheck the checkbox, the textfields and the select field becomes enabled, just the opposite of what was before the submit button was pressed"!!! Is there any way to make sure if the checkbox is selected certainly the textfields/selectfields are enables and if the checkbox is deselected the textfields/selectfields are disabled?
Here are the two files (the later one 2.html is the one that the form in 1.html calls:
***1.html**
<html>
<head>
<title>FASTT</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="fastt.css" type="text/css">
<script language="JavaScript">
<!-- Hide script from older browsers
function fillInputValue(select_box, component_id) {
var user_choice = select_box.options[select_ box.select edIndex].v alue
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu m+1, user_choice.length)
}
eval("document.forms[0].C_ " + component_id + ".value = \"" + user_choice1 + "\"")
eval("document.forms[0].V_ " + component_id + ".value = \"" + user_choice2 + "\"")
}
function setSelectValue(select_box, component_id) {
var user_choice = select_box.options[select_ box.select edIndex].v alue
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu m+1, user_choice.length)
}
var target_select = eval("document.forms[0].C_ " + component_id)
for (var i = 0; i < target_select.length; i++) {
if (target_select.options[i]. value == user_choice1) {
target_select.options[i].s elected = true
eval("document.forms[0].V_ " + component_id + ".value = \"" + user_choice2 + "\"")
break
}
}
}
// End hiding script -->
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="model_config_create" method="post" action="2.html">
<input type="hidden" name="w_components" value="8|DCComp3|C_31"><ta ble>
<tr>
<td class="content_field_label " valign="top" width="100"><input type="checkbox"
name="R_31" value="ON"
onClick="C_31.disabled=!C_ 31.disable d;V_31.dis abled=!V_3 1.disabled ;select_31 _1.disable d=!select_ 31_1.disab led;C_31.v alue='';V_ 31.value=' '"></td>
</td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="text" name="C_31" size="45" maxlength="128" disabled> <b>Version:</b >
<input type="text" name="V_31" size="25" maxlength="128" disabled> </td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" class="content_field_label ">Candidat e #1:</td>
<td><select name="select_31_1" onChange="fillInputValue(t his, 31)" size="1" disabled>
<option value>(Choose One)</option>
<option value="HE:V">HE:V</option>
<option value="HEHE:HE_V">HE:HE_V< /option>
<option value="HI124:HI124_V">HI12 4:HI124_V< /option>
</select> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<input type=submit value=Submit>
</form>
</body>
</html>
***1.html***
***2.html***
<html>
<body>
2.html
</body>
</html>
***2.html**
-tooki
Here are the two files (the later one 2.html is the one that the form in 1.html calls:
***1.html**
<html>
<head>
<title>FASTT</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="fastt.css" type="text/css">
<script language="JavaScript">
<!-- Hide script from older browsers
function fillInputValue(select_box,
var user_choice = select_box.options[select_
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu
}
eval("document.forms[0].C_
eval("document.forms[0].V_
}
function setSelectValue(select_box,
var user_choice = select_box.options[select_
var mynum = user_choice.indexOf(":")
if (mynum == -1 )
{
var user_choice1 = user_choice
var user_choice2 = ""
}
else
{
var user_choice1 = user_choice.substring(0, mynum)
var user_choice2 = user_choice.substring(mynu
}
var target_select = eval("document.forms[0].C_
for (var i = 0; i < target_select.length; i++) {
if (target_select.options[i].
target_select.options[i].s
eval("document.forms[0].V_
break
}
}
}
// End hiding script -->
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="model_config_create"
<input type="hidden" name="w_components" value="8|DCComp3|C_31"><ta
<tr>
<td class="content_field_label
name="R_31" value="ON"
onClick="C_31.disabled=!C_
</td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="text" name="C_31" size="45" maxlength="128" disabled> <b>Version:</b
<input type="text" name="V_31" size="25" maxlength="128" disabled> </td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" class="content_field_label
<td><select name="select_31_1" onChange="fillInputValue(t
<option value>(Choose One)</option>
<option value="HE:V">HE:V</option>
<option value="HEHE:HE_V">HE:HE_V<
<option value="HI124:HI124_V">HI12
</select> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<input type=submit value=Submit>
</form>
</body>
</html>
***1.html***
***2.html***
<html>
<body>
2.html
</body>
</html>
***2.html**
-tooki
ASKER
Anyone....to help!!!
thanks,-tooki
thanks,-tooki
Define Action on Body onLoad
<Body onLoad = "whatever.checked=true">
OR
<Body onLoad="document.forms['my Form'].res et()">
<Body onLoad = "whatever.checked=true">
OR
<Body onLoad="document.forms['my
ASKER
Thanks Adilkhan!
I tried <Body onLoad="document.forms['my Form'].res et()">
Ok it keeps the checked checkbox checked when hit browser back button and it keeps unchecked checkbox unchecked,ok!
But how any textfield (that contains values before submitting the form) that are enabled before submit gets disabled after coming back using browser back button. How can I keep that same enabled status for the textfields (also the selectbox)?
thanks.
-tooki
I tried <Body onLoad="document.forms['my
Ok it keeps the checked checkbox checked when hit browser back button and it keeps unchecked checkbox unchecked,ok!
But how any textfield (that contains values before submitting the form) that are enabled before submit gets disabled after coming back using browser back button. How can I keep that same enabled status for the textfields (also the selectbox)?
thanks.
-tooki
use the Same Function and Populate the Form Field's Status on Body onLoad
function default_vals()
function default_vals()
use the Same Function and Populate the Form Field's Status on Body onLoad
function default_vals() {
// whatever you want to enable/disable
}
<body onLoad="default_vals()">
function default_vals() {
// whatever you want to enable/disable
}
<body onLoad="default_vals()">
ASKER
Thanks.But I wrote the <body onLoad="default_vals()"> but I wrote below the default_vals() function but still the textfield C_31 andselect field select_31_1 always get disabled after I come back after the form submission,could you please help me with the syntax in the default_vals() function bolow:
function default_vals() {
document.forms['myForm'].r eset()
document.forms['myForm'].C _31.disabl ed=!docume nt.forms[' myForm'].C _31.disabl ed
document.forms['myForm'].s elect_31_1 .disabled= !document. forms['myF orm'].sele ct_31_1.di sabled
}
Thanks!-tooki
function default_vals() {
document.forms['myForm'].r
document.forms['myForm'].C
document.forms['myForm'].s
}
Thanks!-tooki
function default_vals() {
document.forms['myForm'].r eset();
document.forms['myForm'].C _31.disabl ed=false;
document.forms['myForm'].s elect_31_1 .disabled= false;
}
document.forms['myForm'].r
document.forms['myForm'].C
document.forms['myForm'].s
}
ASKER
Thanks.
But still this function default_vals() cannot enable the textfield C_31 and the select field select_31_1 (if they were enabled before the form submission).
I think this is because in the form the textfields/selectfield are craeated as 'disabled' by default:
<input type="text" name="V_31" size="25" maxlength="128" disabled>
<select name="select_31_1" onChange="fillInputValue(t his, 31)" size="1" disabled>
...
-tooki
But still this function default_vals() cannot enable the textfield C_31 and the select field select_31_1 (if they were enabled before the form submission).
I think this is because in the form the textfields/selectfield are craeated as 'disabled' by default:
<input type="text" name="V_31" size="25" maxlength="128" disabled>
<select name="select_31_1" onChange="fillInputValue(t
...
-tooki
yes tooki, you are right.
You can take out disabled from the Text input type and select field and populate them in a function instead.
You can take out disabled from the Text input type and select field and populate them in a function instead.
ASKER
No,actually it does not work for me. When we load the html page (1.html) fro the first time, I need everything disabled (V_31 disabled, select_31_1 disabled and R_31 unchecked).
Before I hit "submit" in 1.html, if R_31 is checked (i.e. V_31 enabled, select_31_1 enabled), I need to see R_31 checked, V_31 enabled and select_31_1 enabled after the "submit" in 1.html is pressed and I used the browser "Back" button to come back to "1.html".
If in 1.html I write:
<input type="text" name="V_31" size="25" maxlength="128">
<select name="select_31_1" onChange="fillInputValue(t his, 31)" size="1">
(Instead of: <input type="text" name="V_31" size="25" maxlength="128" disabled>
<select name="select_31_1" onChange="fillInputValue(t his, 31)" size="1" disabled>
)
then at the beginning (when 1.html is called) V_31 enabled and select_31_1 enabled will be enabled and I do not want that.
Is there any way to have it done...
Thanks.-tooki
Before I hit "submit" in 1.html, if R_31 is checked (i.e. V_31 enabled, select_31_1 enabled), I need to see R_31 checked, V_31 enabled and select_31_1 enabled after the "submit" in 1.html is pressed and I used the browser "Back" button to come back to "1.html".
If in 1.html I write:
<input type="text" name="V_31" size="25" maxlength="128">
<select name="select_31_1" onChange="fillInputValue(t
(Instead of: <input type="text" name="V_31" size="25" maxlength="128" disabled>
<select name="select_31_1" onChange="fillInputValue(t
)
then at the beginning (when 1.html is called) V_31 enabled and select_31_1 enabled will be enabled and I do not want that.
Is there any way to have it done...
Thanks.-tooki
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:
Split: GwynforWeb {http:#9872237} & adilkhan {http:#9872241} & Timbo87 {http:#9872449} & sajuks {http:#9873001}
Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jAy
EE Cleanup Volunteer
I will leave the following recommendation for this question in the Cleanup topic area:
Split: GwynforWeb {http:#9872237} & adilkhan {http:#9872241} & Timbo87 {http:#9872449} & sajuks {http:#9873001}
Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jAy
EE Cleanup Volunteer