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
    Regular Coder
    Join Date
    Jul 2002
    Posts
    362
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Validating Selected Drop Down

    Trying to validate Selected drop down in my Cold Fusion for Netscape 4.77 browser:

    Code:
    Network<BR>
    <P><SELECT MULTIPLE NAME="network">
    <!-- <OPTION VALUE="TBD" SELECTED>Select Options:</OPTION> -->
    <cfquery name="listNet" datasource="mydatabasename" dbtype="ODBC">
    select *
    from network_table
    </cfquery>
    <CFOUTPUT QUERY="listNet">
    <OPTION VALUE="#network#">#network#</OPTION>
    </CFOUTPUT>
    </SELECT>&nbsp;</P>
    I tried this with JavaScript:
    Code:
    function Val()
    {
         if(document.myFormName.network.selectedIndex == 0)
         {
                  alert('Select a network\n');
         }
    }
    
    <cfform action = "myformaction.cfm" name = "myFormName" onSubmit = "return Val();">
    The above didnt work. Please advise.

  • #2
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Any time you attempt to integrate ColdFusion's automatic form scripting (via the <cfform> tag), you're asking for ridiculous complications regarding any customized scripting. If you're to use the <cfform> tag, also use the <cf{INPUTTYPE}> tags:
    Code:
    <cfform name="myForm" action="form.cfm">
        <cfselect name="mySelect" required="Yes" ... />
    ...
    Check the docs when you have questions. Otherwise, dropping the <cfform> tag for the reg'lar old <form> tag leaves your scripting totally up to you. Pass in a reference and it's that much easier.
    Code:
    function Val(evt, f) {
       if ( 1 > f.elements['mySelect'].selectedIndex) {
          alert('Please select an option.');
          return false;
       }
    }
    {...}
    <form action="form.cfm" name="myForm" onsubmit="return Val(event, this);">
       <select name="mySelect">
    ...

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    362
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks!


  •  

    Posting Permissions

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