Matt
Matt

Reputation: 379

Why aren't my radio button.checked comparisons working?

I have three radio buttons that I am working with. No matter which one I select it seems to default to the first one. It's working in regards to actually assigning a value, but the second radio button doesn't seem to be working.

if ($radDB1.Checked = $true){
    $database = 'EXDB01_005'
}
if($radDB2.Checked = $true){
    $database = 'EXDB02_005'
}
if ($radDB5.Checked = $true){
    $database = 'EXDB01_005'
}

They are placed inside a groupbox, which I tried to access here:

switch ($grpEXDatabase)
{
    $radDB1.Checked { $database = 'EXDB01_005' }
    $radDB2.Checked { $database = 'EXDB02_005' }
    $radDB5.Checked { $database = 'EXDB01_005' }
}

This did not work. Anyone know what's going on with this?

Upvotes: 3

Views: 2088

Answers (1)

Jason Snell
Jason Snell

Reputation: 1465

if ($radDB1.Checked -eq $true){
    $database = 'EXDB01_005'
}
if($radDB2.Checked -eq $true){
    $database = 'EXDB02_005'
}
if ($radDB5.Checked -eq $true){
    $database = 'EXDB01_005'
}

The problem with your code is that you're using "=" instead of "-eq" in your if statement. The above should work for checking the value. Otherwise using "=" assigns a value, it doesn't compare it.

Upvotes: 5

Related Questions