...

View Full Version : validation help



esthera
03-17-2009, 09:10 AM
I have a bunch of chexboxes and textboxes




<input name="delete" value="626235" type="checkbox"><br><input name="deletedreason626235" type="text">

<input name="delete" value="626236" type="checkbox"><br><input name="deletedreason626236" type="text">

<input name="delete" value="626237" type="checkbox"><br><input name="deletedreason626237" type="text">

<input name="delete" value="626238" type="checkbox"><br><input name="deletedreason626238" type="text">

I need to do validation that if the checkbox was checked then the corresponding textbox (with the same number must also be checked)

can someone help men with this?

Philip M
03-17-2009, 09:28 AM
I need to do validation that if the checkbox was checked then the corresponding textbox (with the same number must also be checked)



What does that mean? Completed? Enabled? Disabled?


Quizmaster: In 1985 the first black player to win the Wimbledon men's singles title was Arthur who?
Contestant: Askey

esthera
03-17-2009, 09:31 AM
if the checkbox is checked - then the textbox with the same number must not be blank

Philip M
03-17-2009, 10:06 AM
626235 <input name="delete" id = "d1" value="626235" type="checkbox" onchange = "confirmreason(this)"><input id="deletedreason626235" type="text"><br>

626236 <input name="delete" id = "d2" value="626236" type="checkbox" onchange = "confirmreason(this)"><input id = "deletedreason626236" type="text"><br>

626237 <input name="delete" id = "d3" value="626237" type="checkbox" onchange = "confirmreason(this)"><input id = "deletedreason626237" type="text"><br>

626328 <input name="delete" id= "d4" value="626238" type="checkbox" onchange = "confirmreason(this)"><input id = "deletedreason626238" type="text"><br>

<script type = "text/javascript">

function confirmreason(which) {
var n = "deletedreason" + which.value;
var x = document.getElementById(n).value;
x = x.replace(/^\s+|\s+$/g,""); // strip leading and trailing spaces;
if (x.length < 6) { // minimum six characters for reason
alert ("You must specify the reason \(minimum 6 characters\) before you can check the checkbox");
var boxid = which.id;
document.getElementById(boxid).checked = false;
return false;
}

}

</script>


But why have checkboxes at all? Or if the textbox has been filled (not blank), then regard the corresponding checkbox as checked. On your page layout the user will naturally check the checkbox before entering the reason, so the textbox will always be blank and he is bound to receive an error message.




The older I grow the more I distrust the familiar doctrine that age brings wisdom. - H.L. Mencken 1880-1956, American Editor, Author, Critic, Humorist

Philip M
03-17-2009, 10:50 AM
The following moves the focus to the related textbox if the checkbox is checked, and requires an entry of six characters minimum before the user can proceed. The text entry can be deleted again if the checkbox is first unchecked.


626235 <input name="delete" id = "d626235" value="626235" type="checkbox" onclick = "confirmreason(this)"><input id="deletedreason626235" type="text" onblur = "checkreason(this)"><br>

626236 <input name="delete" id = "d626236" value="626236" type="checkbox" onclick = "confirmreason(this)"><input id = "deletedreason626236" type="text" onblur = "checkreason(this)"><br>

626237 <input name="delete" id = "d626237" value="626237" type="checkbox" onclick = "confirmreason(this)"><input id = "deletedreason626237" type="text" onblur = "checkreason(this)"><br>

626328 <input name="delete" id= "d626238" value="626238" type="checkbox" onclick = "confirmreason(this)"><input id = "deletedreason626238" type="text" onblur = "checkreason(this)"><br>

<script type = "text/javascript">

function confirmreason(which) {

var a = which.value;
var b = which.id;
var n = "deletedreason" + a;
var x = document.getElementById(n).value;
x = x.replace(/^\s+|\s+$/g,""); // strip leading and trailing spaces;
if (document.getElementById(b).checked == false) {
document.getElementById(n).value = "";
return false;
}
if (x.length <6) {
document.getElementById(n).focus();
}
}

function checkreason(which) {

var x = which.value;
b = which.id;
b = b.replace(/eletedreason/,"")

if (document.getElementById(b).checked == false) {
if (x.length > 0) {
alert ("You must check the checkbox before you enter a reason" );
which.value = "";
return false;
}
}

if (document.getElementById(b).checked) {
x = x.replace(/^\s+|\s+$/g,""); // strip leading and trailing spaces;
if (x.length < 6) {
alert ("You must enter a reason for deleting this item \(6 characters minimum\)");
which.focus();
return false;
}
}

}

</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum