PDA

View Full Version : Valadation/Toggle View turn on/off fields



Macca
02-12-2009, 09:24 PM
Trying to get the code below to work. Basicaly it is two things. Hide/Show fields by selcting a radio button. The textboxes that are displayed will have valadation to make sure they are completed. Also one of the textboxes (textboxa) is available within all displays. Any help much appreciated.

JavaScript code:

// 1. What Have they answered
// which one is checked
//Answering as a
if (theForm.faspath[1].checked) {
if (! !theForm.textbox1.value==""){
alert ("Please give an answer to :");
theForm.textbox.focus();
return false;
}

if (! !theForm.textboxa.value=="")
{
alert ("Please give an answer to:");
theForm.textboxa.focus();
return false;
}
}
}
else
{
// Answering as b
if (theForm.faspath[2].checked) {
if (! !theForm.textbox2.value==""){
alert ("Please give an answer to :");
theForm.textbox2.focus();
return false;
}

if (! !theForm.textboxa.value=="")
{
alert ("Please give an answer :");
theForm.textboxa.focus();
return false;
}
else
{
// Answering as c
if (theForm.faspath[3].checked) {
if (! !theForm.textbox3.value==""){
alert ("Please give an answer to Date of :");
theForm.textbox3.focus();
return false;
}

if (! !theForm.textbox4.value=="")
{
alert ("Please give an answer to :");
theForm.textbox4.focus();
return false;
}
if (! !theForm.textbox5.value==""){
alert ("Please give an answer to :");
theForm.textbox5.focus();
return false;
}

if (! !theForm.textbox5.value=="")
{
alert ("Please give an answer to :");
theForm.textbox5.focus();
return false;
}
if (! !theForm.textbox6.value=="")
{
alert ("Please give an answer to :");
theForm.textbox6.focus();
return false;
}
if (! !theForm.textbox7.value=="")
{
alert ("Please give an answer to :");
theForm.textbox7.focus();
return false;
}
if (! !theForm.textboxa.value=="")
{
alert ("Please give an answer to :");
theForm.textboxa.focus();
return false;
}

}

}



function toggleCust(state) {

// Turn on / off the fields

//clear all fields
document.getElementById("textbox1").value =="";
document.getElementById("textboxa").value == "";

document.getElementById("textbox1").disabled = true;
document.getElementById("textboxa").disabled = true;

}

function toggleUnder(state) {

// Turn on / off the fields

//clear all the fields
document.getElementById("textbox2").value =="";
document.getElementById("textboxa").value == "";

document.getElementById("textbox2").disabled = true;
document.getElementById("textboxa").disabled = true;

}

function toggleCase(state) {

// Turn on / off the fields

//clear all the fields
document.getElementById("textbox3").value =="";
document.getElementById("textbox4").value == "";
document.getElementById("textbox5").value =="";
document.getElementById("textbox6").value == "";
document.getElementById("textbox7").value =="";
document.getElementById("textboxa").value == "";

document.getElementById("textbox3").disabled = true;
document.getElementById("textbox4").disabled = true;
document.getElementById("textbox5").disabled = true;
document.getElementById("textbox6").disabled = true;
document.getElementById("textbox7").disabled = true;
document.getElementById("textboxa").disabled = true;
}


</script>

I use below to 'toggle' the views.
input type="radio" name="faspath" id="faspath1" onClick="toggleCust(true); toggleUnder(false); toggleCase(false);">
<input name="tetxbox1" type="text" class="input" id="tetxbox1" value="" size="25" /></td> and so on.........

Macca
02-16-2009, 10:12 PM
Can anyone help me with this or recommend another solution?

thanks

Macca
02-26-2009, 04:24 PM
Sorry to keep going back to this but can anyone help me with this? Or as I have previously stated another way to do this? Please someone help.