Hi All,
I have a form with a couple of list fields, if the user needs to add something that is not on the list I have a choice value "other", on change, a text field is displayed for typed input.
Problem : Can I hide the associated text with the field? And how, with the script I have...?
Sorry for the big dump, there is lots of validation/translation for the rest of the form not included here. I have stripped out most of the HTML, but left the JS so as not to jip anyone! View it in a browser, the form is very simple...
Thanks, Truck
Here is the HTML:
<html>
<head>
<title>TESSIE Instructor Console</title>
<script language="JavaScript" >
<!--
function xsl() {
xmlSource = new ActiveXObject("Microsoft.x
mldom");
xmlSource.async = false;
xmlSource.load("xml/header
.xml");
xslStyle = new ActiveXObject("Microsoft.x
mldom");
xslStyle.async = false;
xslStyle.load("xml/header.
xsl");
document.all.item("xslHead
er").inner
HTML =
xmlSource.transformNode(xs
lStyle.doc
umentEleme
nt);
}
//-->
</script>
<style type="text/css">
.invisible { visibility: hidden;}
.visible {visibility: visible;}
</style>
<SCRIPT>
<!-- Hide from older browsers
function DateToday() {
var Today=new Date();
var ThisDay=Today.getDate();
var ThisMonth=Today.getMonth()
+1;
var ThisYear=Today.getFullYear
();
return ThisMonth+"-"+ThisDay+"-"+
ThisYear;
}
function today() {
document.Form_cust.date.va
lue=DateTo
day();
}
function day_of_class() {
document.Form_cust.day_of_
class.valu
e=getCooki
e('day_of_
class');
}
//Stop hiding -->
</SCRIPT>
<SCRIPT LANGUAGE = "JavaScript">
<!-- Begin
var expDays = 90; // set this value to however many days you want your cookies to last
function setCookie(name, val)
{
var exp = new Date()
var cookieTimeToLive = exp.getTime() + (expDays * 24 * 60 * 60 * 1000)
exp.setTime(cookieTimeToLi
ve)
document.cookie = name + "=" + escape(val) + "; expires=" + exp.toGMTString()
}
function getCookie(name)
{
var cookieNameLen = name.length
var cLen = document.cookie.length
var i = 0
var cEnd
var myStringToReturn
var myStringToReturnLen
while (i < cLen)
{
var j = i + cookieNameLen
if (document.cookie.substring
(i,j) == name)
{
cEnd = document.cookie.indexOf(";
",j)
if (cEnd == -1)
{
cEnd = document.cookie.length
}
myStringToReturn = unescape(document.cookie.s
ubstring(j
,cEnd))
myStringToReturnLen = myStringToReturn.length
myStringToReturn = myStringToReturn.substring
(1,myStrin
gToReturnL
en+1)
return myStringToReturn
}
i++
}
return ""
}
function setDefaultValues()
{
var strCookieName, strCookieVal
var iFormsCount = 0
var iElementsCount = 0
for(iFormsCount=0;iFormsCo
unt < document.forms.length;iFor
msCount++)
{
for(iElementsCount=0;iElem
entsCount < document.forms[iFormsCount
].elements
.length;iE
lementsCou
nt++)
{
strCookieName = document.forms[iFormsCount
].elements
[iElements
Count].nam
e
strCookieVal = getCookie(strCookieName)
if (strCookieVal != null && !(isNaN(strCookieVal)) && strCookieVal != '')
{
document.forms[iFormsCount
].elements
[iElements
Count].sel
ectedIndex
= strCookieVal
}
}
}
}
function replaceChars( foo )
{
for( i=0; i<foo.length; i++ )
{
var c = foo.charAt( i );
if( c == '&' )
{
foo = foo.substring( 0 ,i ) + "&" + foo.substring( i + 1, foo.length );
} else if( c == '<' )
{
foo = foo.substring( 0 ,i ) + "<" + foo.substring( i + 1, foo.length );
} else if( c == '>' )
{
foo = foo.substring( 0 ,i ) + ">" + foo.substring( i + 1, foo.length );
}
}
return foo;
}
function translate()
{
Form_cust.customer.value = replaceChars( Form_cust.customer.value );
}
// End -->
</SCRIPT>
<script language="JavaScript">
<!--
function chkOther(selval, field)
{
if (!selval) return;
else {
var bWhich = (selval == 'other');
field.className = (bWhich) ? 'visible' : 'invisible';
field.disabled = !bWhich;
if (bWhich) field.value = '';
if (bWhich) field.focus();
;
}
}
function runSubmit (form, button) {
Ctrl = form.instructor.selectedIn
dex
if (form.instructor.options[C
trl].value
== "") {
validatePromt(Ctrl,"Please
Select Your Name");
return (false);
}
Ctrl = form.region.selectedIndex
if (form.region.options[Ctrl]
.value == "")
{
validatePromt(Ctrl,"Please
Select Your Region");
return (false);
}
else {
setCookie('region',form.re
gion.selec
tedIndex);
}
Ctrl = form.date;
if (Ctrl.value =="") {
validatePromt(Ctrl,"Please
Enter a Date");
return (false);
}
else {setCookie('date', DateToday());}
Ctrl = form.course.selectedIndex
if (form.course.options[Ctrl]
.value == "") {
validatePromt(Ctrl,"Please
Select a Course");
return (false);
}
Ctrl = form.day_of_class;
if (Ctrl.value == "") {
validatePromt(Ctrl,"Please
select the number of days.");
return (false);
}
else{ setCookie('day_of_class',f
orm.course
.options[f
orm.course
.selectedI
ndex].valu
e1)}
Ctrl = form.location2;
if (Ctrl.value == "none") {
validatePromt(Ctrl,"Please
select a location.");
return (false);
}
else if (form.location2.value!="ot
her"){
form.location.value=form.l
ocation2.v
alue;
}
if ((form.location2.value=="o
ther") && (form.customer.value == "")) {
validatePromt(Ctrl,"Please
Enter the Customer Information.");
return (false);
}
else if ((form.location2.value=="o
ther") && (form.customer.value != "")) {
form.location.value=form.c
ustomer.va
lue;
}
var check_date = getCookie('date')
var check_inst =getCookie('instructor')
var check_course =getCookie('course')
if ( ( form.instructor.selectedIn
dex == check_inst ) && ( form.course.selectedIndex == check_course ) &&(check_date == DateToday()) )
if (confirm("\nYou're about to submit the form. It appears you have already saved \na class with this configuration. If you continue, saved data could be lost. \n\nClick on OK to submit.\n\nClick on Cancel to abort."))
{
alert("\nYour submission will now be made to data file, Thank you!");
document.Form_cust.submit(
);
return (true);
}
else
{
alert("\nYou have chosen to abort the submission.");
return (false);
}
else {document.Form_cust.submit
();
setCookie('instructor',for
m.instruct
or.selecte
dIndex);
setCookie('course',form.co
urse.selec
tedIndex);
return (true); }
}
function validatePromt(Ctrl, PromtStr) {
alert (PromtStr);
// Ctrl.focus();
return(true);
}
function ShowAlert()
{
var check_date = getCookie('date')
var check_inst =getCookie('instructor')
var check_course =getCookie('course')
alert (document.cookie)
alert (document.Form_cust.course
.selectedI
ndex)
if ( ( document.Form_cust.instruc
tor.select
edIndex == check_inst ) && ( document.Form_cust.course.
selectedIn
dex == check_course ) &&(check_date == DateToday()) )
{ alert ("\nClass Date:",check_course)
}
else {alert (document.Form_cust.course
.selectedI
ndex)}
}
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&p
arent.fram
es.length)
{
d=parent.frames[n.substrin
g(p+1)].do
cument; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;
i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.
layers.len
gth;i++) x=MM_findObj(n,d.layers[i]
.document)
;
if(!x && document.getElementById) x=document.getElementById(
n); return x;
}
//-->
</script>
<script language="JavaScript1.2">
<!--
function refresh()
{
window.location.reload( false );
}
//-->
</script>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(p
arseInt(ap
pVersion)=
=4)) {
document.MM_pgW=innerWidth
; document.MM_pgH=innerHeigh
t; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_p
gW || innerHeight!=document.MM_p
gH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<LINK href="standard.css" type=text/css rel=stylesheet>
<body onLoad="xsl();setDefaultVa
lues();tod
ay();day_o
f_class()"
>
<form name="Form_cust" method="post" action="/servlet/InstSetup
" >
<table width="59%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td><strong>Instructor Name: </strong> </td>
<td><strong>Please enter name:</strong></td>
<td> </td>
</tr>
<tr>
<td><select name="instructor2" onChange="chkOther(options
[selectedI
ndex].valu
e,instruct
or)">
<option value="" selected>Select Your Name
<option value="Sally">Sally</optio
n>
<option value="Joe">Joe</option>
<option value="other">Not on&
nbsp;List?
</option>
</select> </td>
<td><input type="text" value="Type your name here." name="instructor" class="invisible" disabled="disabled"></td>
<td> </td>
</tr>
<script>
function openObject(someID)
{
document.getElementById(so
meID).styl
e.visibili
ty = 'visible';
}
</script>
<tr>
<td width="156"><b>Location:</
b> <input type="hidden" name="location"> </td>
<td width="198"><b>Customer Info:</b> </td>
<td > </td>
</tr>
<tr>
<td height="24"> <select name="location2" onChange="chkOther(options
[selectedI
ndex].valu
e,customer
)">
<option value="none" selected>Choose Location</option>
<option value="TLC-PA-Sapphire">TL
C-PA-Sapph
ire</optio
n>
<option value="TLC-PA-Emerald">TLC
-PA-Emeral
d</option>
<option value="other">On-Site(Add Cust)</option>
</select> </td>
<td width="198"><input type="text" value="Please enter customer name" label="AAA" name="customer" class="invisible"disabled=
"disabled"
></td>
<td ><input name="Button" type="button"
onClick="translate(); runSubmit(this.form,this);
" value="Setup"></td>
</tr>
</table>
</form>
</body>
</html>
Start Free Trial