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
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    Select Box problem?

    Hello,
    I'm building a select box in javascript for a search form.
    my problem is selected the default option.

    values:
    Option(text, value, defaultSelected, selected)

    If set both defaultSelected & selected to True.
    but, for some reason, it selects the one above it instead.
    as you can see from the example below, the option "invoice" should be selected, but it's not, instead "sales order" is selected.

    OK, now thats what happens on page load.
    BUT, if i click any of the check boxes on the form, then uncheck them, it resets the select box to the correct option.

    my script:
    PHP Code:

    function CheckFilters(){

    // Check that if any of the additional filters are selected,
    // Then set the Form Type to only Estimates,
    // and Set back again if none are selected.

        
    var numCloseEstimates document.filter.CloseEstimates
        
    var numEstimatesConverted document.filter.EstimatesConverted
        
    var numAvticeEstimates document.filter.AvticeEstimates
        
    var numFormType document.filter.FormType

        
    if(numCloseEstimates.checked || numEstimatesConverted.checked || numAvticeEstimates.checked){
            
    numFormType.options.length=0
            numFormType
    .options[0]=new Option("Estimate""1"falsefalse)
        }else if(!
    numCloseEstimates.checked && !numEstimatesConverted.checked && !numAvticeEstimates.checked){
            
    numFormType.options.length=0
            numFormType
    .options[0]=new Option("All""0"falsefalse)
            
    numFormType.options[1]=new Option("Estimate""1",  falsefalse)
            
    numFormType.options[2]=new Option("Sales Order""2"falsefalse)
            
    numFormType.options[3]=new Option("Invoice""3",  truetrue)
        }


    does any one have any ideas whats going on here?

    thanks in advance for your time!
    -Ken

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Not enough information. The following example works as expected.

    Code:
    <html>
    <head>
    <script language="javascript">
    
    function CheckFilters(){
    
    // Check that if any of the additional filters are selected,
    // Then set the Form Type to only Estimates,
    // and Set back again if none are selected.
    
        var numCloseEstimates = document.filter.CloseEstimates
        var numEstimatesConverted = document.filter.EstimatesConverted
        var numAvticeEstimates = document.filter.AvticeEstimates
        var numFormType = document.filter.FormType
    
        if(numCloseEstimates.checked || numEstimatesConverted.checked || numAvticeEstimates.checked){
            numFormType.options.length=0
            numFormType.options[0]=new Option("Estimate", "1", false, false)
        }else if(!numCloseEstimates.checked && !numEstimatesConverted.checked && !numAvticeEstimates.checked){
            numFormType.options.length=0
            numFormType.options[0]=new Option("All", "0", false, false)
            numFormType.options[1]=new Option("Estimate", "1",  false, false)
            numFormType.options[2]=new Option("Sales Order", "2", false, false)
            numFormType.options[3]=new Option("Invoice", "3",  true, true)
        }
    
    }  
    
    </script>
    
    </head>
    
    <body onload="CheckFilters();">
    
    <form name="filter">
    
    <input type="checkbox" name="CloseEstimates">numCloseEstimates<br>
    <input type="checkbox" name="EstimatesConverted">numEstimatesConverted<br>
    <input type="checkbox" name="AvticeEstimates">numAvticeEstimates<br>
    
    <select name="FormType">
    
    </select>
    
    <input type="submit">
    </form>
    
    </body>
    
    </html>

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    kool, yah i got it working just a few minutes ago,

    PHP Code:
    function CheckFilters(){

    // Check that if any of the additional filters are selected,
    // Then set the Form Type to only Estimates,
    // and Set back again if none are selected.

        
    var numCloseEstimates document.filter.CloseEstimates
        
    var numEstimatesConverted document.filter.EstimatesConverted
        
    var numAvticeEstimates document.filter.AvticeEstimates
        
    var numFormType document.filter.FormType

        
    // Handle checkboxes, only one can be checked at a time
        
    if(numCloseEstimates.checked){
            
    numEstimatesConverted.disabled true
            numAvticeEstimates
    .disabled true
        
    }else if(!numCloseEstimates.checked){
            
    numEstimatesConverted.disabled false
            numAvticeEstimates
    .disabled false
            
    //next check box
            
    if(numEstimatesConverted.checked){
                
    numCloseEstimates.disabled true
                numAvticeEstimates
    .disabled true
            
    }else if(!numEstimatesConverted.checked){
                
    numCloseEstimates.disabled false
                numAvticeEstimates
    .disabled false
                
    //next check box
                
    if(numAvticeEstimates.checked){
                    
    numCloseEstimates.disabled true
                    numEstimatesConverted
    .disabled true
                
    }else if(!numAvticeEstimates.checked){
                    
    numCloseEstimates.disabled false
                    numEstimatesConverted
    .disabled false
                
    }
            }
        }

        if(
    numCloseEstimates.checked || numEstimatesConverted.checked || numAvticeEstimates.checked){
            
    numFormType.options.length=0
            numFormType
    .options[0]=new Option("Estimate""1"falsefalse)
        }else if(!
    numCloseEstimates.checked && !numEstimatesConverted.checked && !numAvticeEstimates.checked){
            
    numFormType.options.length=0
            numFormType
    .options[0]=new Option("All""0", <% If request("FormType") = "0" Then response.write "false, true" Else response.write "false, false" End If %>)
            
    numFormType.options[1]=new Option("Estimate""1",  <% If request("FormType") = "1" Then response.write "false, true" Else response.write "false, false" End If %>)
            
    numFormType.options[2]=new Option("Sales Order""2", <% If request("FormType") = "2" Then response.write "false, true" Else response.write "false, false" End If %>)
            
    numFormType.options[3]=new Option("Invoice""3",  <% If request("FormType") = "3" Then response.write "false, true" Else response.write "false, false" End If %>)
        }



    fun with javascript:-)

    -Ken


  •  

    Posting Permissions

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