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.xmldom");
xmlSource.async = false;
xmlSource.load("xml/header.xml");
xslStyle = new ActiveXObject("Microsoft.xmldom");
xslStyle.async = false;
xslStyle.load("xml/header.xsl");
document.all.item("xslHeader").innerHTML =
xmlSource.transformNode(xslStyle.documentElement);
}
//-->
</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.value=DateToday();
}
function day_of_class() {
document.Form_cust.day_of_class.value=getCookie('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(cookieTimeToLive)
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.substring(j,cEnd))
myStringToReturnLen = myStringToReturn.length
myStringToReturn = myStringToReturn.substring(1,myStringToReturnLen+1)
return myStringToReturn
}
i++
}
return ""
}
function setDefaultValues()
{
var strCookieName, strCookieVal
var iFormsCount = 0
var iElementsCount = 0
for(iFormsCount=0;iFormsCount < document.forms.length;iFormsCount++)
{
for(iElementsCount=0;iElementsCount < document.forms[iFormsCount].elements.length;iElementsCount++)
{
strCookieName = document.forms[iFormsCount].elements[iElementsCount].name
strCookieVal = getCookie(strCookieName)
if (strCookieVal != null && !(isNaN(strCookieVal)) && strCookieVal != '')
{
document.forms[iFormsCount].elements[iElementsCount].selectedIndex = 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.selectedIndex
if (form.instructor.options[Ctrl].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.region.selectedIndex);
}
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',form.course.options[form.course.selectedIndex].value1)}
Ctrl = form.location2;
if (Ctrl.value == "none") {
validatePromt(Ctrl,"Please select a location.");
return (false);
}
else if (form.location2.value!="other"){
form.location.value=form.location2.value;
}
if ((form.location2.value=="other") && (form.customer.value == "")) {
validatePromt(Ctrl,"Please Enter the Customer Information.");
return (false);
}
else if ((form.location2.value=="other") && (form.customer.value != "")) {
form.location.value=form.customer.value;
}
var check_date = getCookie('date')
var check_inst =getCookie('instructor')
var check_course =getCookie('course')
if ( ( form.instructor.selectedIndex == 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',form.instructor.selectedIndex);
setCookie('course',form.course.selectedIndex);
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.selectedIndex)
if ( ( document.Form_cust.instructor.selectedIndex == check_inst ) && ( document.Form_cust.course.selectedIndex == check_course ) &&(check_date == DateToday()) )
{ alert ("\nClass Date:",check_course)
}
else {alert (document.Form_cust.course.selectedIndex)}
}
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; 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.length;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")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<LINK href="standard.css" type=text/css rel=stylesheet>
<body onLoad="xsl();setDefaultValues();today();day_of_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[selectedIndex].value,instructor)">
<option value="" selected>Select Your Name
<option value="Sally">Sally</option>
<option value="Joe">Joe</option>
<option value="other">Not on 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(someID).style.visibility = '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[selectedIndex].value,customer)">
<option value="none" selected>Choose Location</option>
<option value="TLC-PA-Sapphire">TLC-PA-Sapphire</option>
<option value="TLC-PA-Emerald">TLC-PA-Emerald</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>
by: amit_gPosted on 2003-10-08 at 15:53:28ID: 9517115
Add a function next to chkOther function (you already have chkOther)
eldName);
[selectedI ndex].valu e,instruct or);">
[selectedI ndex].valu e,instruct or);chkOth er2(option s[selected Index].val ue,'Please EnterName' );">
function chkOther2(selval, fieldName)
{
var field = document.getElementById(fi
if (!selval) return;
else {
var bWhich = (selval == 'other');
field.className = (bWhich) ? 'visible' : 'invisible';
}
}
and change
<td><strong>Please enter name:</strong></td>
to
<td><strong><span id="PleaseEnterName" class="invisible">Please enter name:</span></strong></td>
and change
<td><select name="instructor2" onChange="chkOther(options
to
<td><select name="instructor2" onChange="chkOther(options