diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 9a1aeeb5cd0..d1c6c58d832 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -8744,7 +8744,7 @@ class Form
}
} else {
$id = (string) $id; // if $id = 0, then $id = '0'
- if ($id != '' && ($id == $key || ($id == 'ifone' && count($array) == 1)) && !$disabled) {
+ if ($id != '' && (($id == (string) $key) || ($id == 'ifone' && count($array) == 1)) && !$disabled) {
$out .= ' selected'; // To preselect a value
}
}