dcsimg
www.webdeveloper.com
Results 1 to 7 of 7

Thread: Require a field based on another

  1. #1
    Join Date
    Feb 2005
    Posts
    11

    Require a field based on another

    Hi all.
    My first 3 if statements for Name, Department and Date execute correctly.

    The 4th item is a radio button. I want to execute the WithoutContent function on the CPT4 code field only if the radio button for the NewEdit field has a specific value (New Charge Number).

    The way I currently have the code, the WithoutContent function does execute for the CPT4 code field, but regardless of which value the NewEdit field has.

    What am I missing? My code is below.
    Thanks!!
    - Valerie


    <script type="text/javascript" language="JavaScript">
    function CheckRequiredFields() {
    var errormessage = new String();

    // Put field checks below this point.



    if(WithoutContent(document.chargeform.txtSubmitter.value))
    { errormessage += "\n\nPlease Enter Name."; }

    if(WithoutContent(document.chargeform.txtDept.value))
    { errormessage += "\n\nPlease Enter Department."; }

    if(WithoutContent(document.chargeform.txtDate.value))
    { errormessage += "\n\nPlease Enter Date."; }


    if (document.chargeform.NewEdit.value = "New Charge Number") {
    (WithoutContent(document.chargeform.txtCPT4Code.value))
    { errormessage += "\n\nPlease CPT4 Code.";}
    }




    // Put field checks above this point.
    if(errormessage.length > 2) {
    alert('NOTE:' + errormessage);
    return false;
    }
    return true;



    } // end of function CheckRequiredFields()


    function WithoutContent(ss) {
    if(ss.length > 0) { return false; }
    return true;
    }

    function WithoutSelectionValue(ss) {
    for(var i = 0; i < ss.length; i++) {
    if(ss[i].selected) {
    if(ss[i].value.length) { return false; }
    }
    }
    return true;
    }



    </script>

  2. #2
    Join Date
    Apr 2003
    Location
    UK
    Posts
    2,203
    You have missed out an = sign, you need to use the Comparison Operator ==

    Please try the following


    if (document.chargeform.NewEdit.value == "New Charge Number") {
    (WithoutContent(document.chargeform.txtCPT4Code.value))
    { errormessage += "\n\nPlease CPT4 Code.";}
    }

  3. #3
    Join Date
    Feb 2005
    Posts
    11
    Good eye. Thank you. There is still something missing. Adding the extra = , now it appears to skip the CPT4 code validation altogether.

    New Code looks like this:

    <script type="text/javascript" language="JavaScript">
    function CheckRequiredFields() {
    var errormessage = new String();

    // Put field checks below this point.




    if(WithoutContent(document.chargeform.txtSubmitter.value))
    { errormessage += "\n\nPlease Enter Name."; }

    if(WithoutContent(document.chargeform.txtDept.value))
    { errormessage += "\n\nPlease Enter Department."; }

    if(WithoutContent(document.chargeform.txtDate.value))
    { errormessage += "\n\nPlease Enter Date."; }


    if (document.chargeform.NewEdit.value == "New Charge Code") {
    (WithoutContent(document.chargeform.txtCPT4Code.value))
    { errormessage += "\n\nPlease CPT4 Code.";}
    }




    // Put field checks above this point.
    if(errormessage.length > 2) {
    alert('NOTE:' + errormessage);
    return false;
    }
    return true;



    } // end of function CheckRequiredFields()


    function WithoutContent(ss) {
    if(ss.length > 0) { return false; }
    return true;
    }

    function WithoutSelectionValue(ss) {
    for(var i = 0; i < ss.length; i++) {
    if(ss[i].selected) {
    if(ss[i].value.length) { return false; }
    }
    }
    return true;
    }





    </script>

  4. #4
    Join Date
    Sep 2004
    Location
    Midwest
    Posts
    1,629
    <HTML>
    <Head>
    <Script Language=JavaScript>

    var prevChecked = "";

    function WithoutContent(){

    alert()
    }

    function checkRadio(isForm){

    if (prevChecked == true){isForm.txtCPT4Code.checked = false;prevChecked = false}
    else if (prevChecked == false){isForm.txtCPT4Code.checked = true;prevChecked = true}
    currState = isForm.txtCPT4Code.checked;
    testField = isForm.NewEdit.value
    testVal = /new charge number/i.test(testField)
    if (currState && testVal){WithoutContent()}
    }
    </Script>
    </Head>
    <Body>
    <Form name='chargeform'>
    CPT4 Code <input type=radio name='txtCPT4Code' onclick="checkRadio(this.form)"><br><br>
    New Edit <input type=text name='NewEdit' value="New Charge Number" size=20><br>
    </Form>
    </Body>
    </HTML>
    Last edited by Warren86; 02-10-2005 at 06:49 AM.

  5. #5
    Join Date
    Feb 2005
    Posts
    11
    Hi. I'm going to post the entire page of code this time. I couldn't quite follow the last suggestion by Warren, although I thank you for your help. It looks like I didn't explain myself right the first time. Let me try again...

    You will see that the NewEdit field has 2 radio buttons. What I'd like to have happen is when someone chooses New Charge Code radio button, the CPT4 Code text field will also be required. If the user chooses the Edit Charge Code button, then the CPT4 field code does not need to be checked.

    Thanks again to all who are trying to make sense of all this for me.
    I should also probably mention that there are some other files involved in the processing of the form, they format the e:mail and say where to send it. If anyone needs to see these, let me know.


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


    <html>
    <head>
    <title>Affinity Charge Request Form</title>
    <!-- Beginning of JavaScript for checking required fields -->
    <script type="text/javascript" language="JavaScript">
    function CheckRequiredFields() {
    var errormessage = new String();

    // Put field checks below this point.



    if(WithoutContent(document.chargeform.txtSubmitter.value))
    { errormessage += "\n\nPlease Enter Name."; }

    if(WithoutContent(document.chargeform.txtDept.value))
    { errormessage += "\n\nPlease Enter Department."; }

    if(WithoutContent(document.chargeform.txtDate.value))
    { errormessage += "\n\nPlease Enter Date."; }

    if (document.chargeform.NewEdit.value == "New Charge Code") {
    (WithoutContent(document.chargeform.txtCPT4Code.value))
    { errormessage += "\n\nPlease CPT4 Code.";}
    }




    // Put field checks above this point.
    if(errormessage.length > 2) {
    alert('NOTE:' + errormessage);
    return false;
    }
    return true;



    } // end of function CheckRequiredFields()


    function WithoutContent(ss) {
    if(ss.length > 0) { return false; }
    return true;
    }


    function WithoutSelectionValue(ss) {
    for(var i = 0; i < ss.length; i++) {
    if(ss[i].selected) {
    if(ss[i].value.length) { return false; }
    }
    }
    return true;
    }



    </script>


    </head>

    <body>



    <form name="chargeform" method="post" onSubmit="return CheckRequiredFields()" action="http://hhs7/ChargeForm/simplemail.asp">
    <!-- The start of the form shows that we are going to post the result back to the file 'simplemail.asp' -->

    <h2 align="center">Affinity Charge Number Request Form:</h2>

    <p><font color="red" size="+1">Items with * are required for form submission.</font></p>


    <table border="1" width="100%">

    <tr>
    <td width="50%">
    <font color="red">*</font> Submitter: <input type="text" name="txtSubmitter" size="25"><br>
    <font color="red">*</font> Department: <input type="text" name="txtDept" size="25"><br>
    <font color="red">*</font> Date Submitted: <input type="text" name="txtDate" size="25"><br>
    </td>
    <td width="50%">
    &nbsp;Type of Request<br>
    <input type="radio" name="NewEdit" value="New Charge Code">New Charge Number Needed<br>
    <input type="radio" name="NewEdit" value="Edit Charge Code">Edit of Existing Charge Number
    </td>
    </tr>

    <tr>
    <td>
    Charge Code (New or Exisiting):
    </td>
    <td>
    <input type="text" name="txtChargeCode" maxlength="15" size="15" />
    </td>


    </tr>
    <tr>
    <td>
    Description: (Max 30 characters)
    </td>
    <td>
    <input type="text" name="Desc" maxlength="30" size="30" />
    </td>


    </tr>
    <tr>
    <td>
    Patient Price:
    </td>
    <td>
    <input type="text" name="txtPtPrice" maxlength="10" size="10" />
    </td>


    </tr>
    <tr>
    <td>
    CPT4 Code:
    </td>
    <td>
    <input type="text" name="txtCPT4Code" maxlength="10" size="10" />
    </td>


    </tr>
    <tr>
    <td>
    HCPCS Code:
    </td>
    <td>
    <input type="text" name="txtHCPCSCode" maxlength="10" size="10" />
    </td>


    </tr>
    <tr>
    <td>
    UB Rev Code:<br>
    278 - Supply/Implants<br>
    279 - Supply/Other
    </td>
    <td>
    <input type="text" name="txtUBCode" maxlength="10" size="10" />
    </td>


    </tr>
    <tr>
    <td>
    If this is a change in an existing code, please state reason:
    </td>
    <td>
    <textarea name="txtRemarks" cols=50 rows="5"></textarea>
    </td>


    </tr>

    <tr>
    <td colspan="2">

    <p>
    <input type="submit" value="Submit" />
    <input type="reset" value="Clear Entry Fields" />
    </p>
    </form>
    </td>
    </tr>
    <p>For questions about this form, call the Janice at extension 6502.</p>
    </td>
    </tr>
    </table>
    </body>
    </html>
    Last edited by loverso; 02-13-2005 at 04:49 PM.

  6. #6
    Join Date
    Apr 2003
    Location
    UK
    Posts
    2,203
    Please try the following


    <html>
    <head>
    <title>Affinity Charge Request Form</title>

    <script language="JavaScript">
    <!--
    function CheckRequiredFields() {
    errormessage = ""

    if(document.chargeform.txtSubmitter.value==""){
    errormessage += "\n\nPlease Enter Name."
    }

    if(document.chargeform.txtDept.value==""){
    errormessage += "\n\nPlease Enter Department."
    }

    if(document.chargeform.txtDate.value==""){
    errormessage += "\n\nPlease Enter Date."
    }

    if (document.chargeform.NewEdit[0].checked&&document.chargeform.txtCPT4Code.value==""){
    errormessage += "\n\nPlease CPT4 Code."
    }

    if(errormessage.length>0){
    alert(errormessage)
    return false
    }
    else{
    return true
    }

    }
    //-->
    </script>


    </head>

    <body>



    <form name="chargeform" method="post" onSubmit="return CheckRequiredFields()" action="http://hhs7/ChargeForm/simplemail.asp">
    <!-- The start of the form shows that we are going to post the result back to the file 'simplemail.asp' -->

    <h2 align="center">Affinity Charge Number Request Form:</h2>

    <p><font color="red" size="+1">Items with * are required for form submission.</font></p>


    <table border="1" width="100%">

    <tr>
    <td width="50%">
    <font color="red">*</font> Submitter: <input type="text" name="txtSubmitter" size="25"><br>
    <font color="red">*</font> Department: <input type="text" name="txtDept" size="25"><br>
    <font color="red">*</font> Date Submitted: <input type="text" name="txtDate" size="25"><br>
    </td>
    <td width="50%">
    Type of Request<br>
    <input type="radio" name="NewEdit" value="New Charge Code">New Charge Number Needed<br>
    <input type="radio" name="NewEdit" value="Edit Charge Code">Edit of Existing Charge Number
    </td>
    </tr>

    <tr>
    <td>
    Charge Code (New or Exisiting):
    </td>
    <td>
    <input type="text" name="txtChargeCode" maxlength="15" size="15" />
    </td>


    </tr>
    <tr>
    <td>
    Description: (Max 30 characters)
    </td>
    <td>
    <input type="text" name="Desc" maxlength="30" size="30" />
    </td>


    </tr>
    <tr>
    <td>
    Patient Price:
    </td>
    <td>
    <input type="text" name="txtPtPrice" maxlength="10" size="10" />
    </td>


    </tr>
    <tr>
    <td>
    CPT4 Code:
    </td>
    <td>
    <input type="text" name="txtCPT4Code" maxlength="10" size="10" />
    </td>


    </tr>
    <tr>
    <td>
    HCPCS Code:
    </td>
    <td>
    <input type="text" name="txtHCPCSCode" maxlength="10" size="10" />
    </td>


    </tr>
    <tr>
    <td>
    UB Rev Code:<br>
    278 - Supply/Implants<br>
    279 - Supply/Other
    </td>
    <td>
    <input type="text" name="txtUBCode" maxlength="10" size="10" />
    </td>


    </tr>
    <tr>
    <td>
    If this is a change in an existing code, please state reason:
    </td>
    <td>
    <textarea name="txtRemarks" cols=50 rows="5"></textarea>
    </td>


    </tr>

    <tr>
    <td colspan="2">

    <p>
    <input type="submit" value="Submit" />
    <input type="reset" value="Clear Entry Fields" />
    </p>
    </form>
    </td>
    </tr>
    <p>For questions about this form, call the Janice at extension 6502.</p>
    </td>
    </tr>
    </table>
    </body>
    </html>


  7. #7
    Join Date
    Feb 2005
    Posts
    11
    That last post really did the trick... problem solved.

    Thank you all so much for helping.

    - Valerie

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles