...

View Full Version : Select Box problem?



angst
06-29-2006, 05:38 PM
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:



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)
}

}



does any one have any ideas whats going on here?

thanks in advance for your time!
-Ken

arnyinc
06-29-2006, 06:45 PM
Not enough information. The following example works as expected.



<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>

angst
06-29-2006, 06:50 PM
kool, yah i got it working just a few minutes ago,



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", false, false)
}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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum