Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy How to highlight required radio button??

    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>

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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?

  • #3
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •