...

View Full Version : How to highlight required radio button??



S4InT
01-09-2004, 12:02 PM
I need a help,
i use this script and i want to highlight required radio button.
Can somebody tell me how ??
Please :(


Thx

<script language="JavaScript">
<!--

/***********************************************
* Required field(s) validation v1.10- By NavSurf
* Visit Nav Surf at http://navsurf.com
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("FirstName", "LastName");
// Enter field description to appear in the dialog box
var fieldDescription = Array("First Name", "Last Name");
// dialog message
var alertMsg = "Please complete the following fields:\n";

var l_Msg = alertMsg.length;

for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
obj.style.backgroundColor="#FFCCCC";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
obj.style.backgroundColor="#FFCCCC";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
obj.style.backgroundColor="#FFCCCC";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}

if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
return false;
}
}
// -->
</script>



<!--SAMPLE FORM -------------------------------->
<form name="formcheck" onsubmit="return formCheck(this);">
First Name: <input type=text name="FirstName" size="25"><br>
Last Name: <input type=text name="LastName" size="25"><br>
<input type=submit value="Submit Form">
</form>

Spudhead
01-09-2004, 02:58 PM
Well the bit of code that runs if nothing's been ticked (checked? radio'd? selected?) is this:

if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}


so you need to stick some stuff in there. I'm not sure what you mean by "highlight" a radio button, though. Can you point us at an example?

S4InT
01-09-2004, 04:24 PM
Radio button for me mean this:

<input type="radio" name="first" value="1">
<input type="radio" name="first" value="2">

When somebody not check this i want to highlight somehow this "radio", but i don't know how :(. This script doesn't highlight radio button.

Can you help me ??

Thanks for any help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum