You can also store the selected value in a global variable and grab it when needed. This works great when multiple buttons or functions need the same dropdown value.
var selectedCustomerId = '';
function handleSelection(value) {
selectedCustomerId = value;
}
This keeps your existing structure but gives you access to the selected value anywhere in your script. The inline check stops ProcessForm from running with empty values. I’ve used this pattern tons of times in legacy apps where I couldn’t restructure the existing markup.
Don’t hardcode the selected value in your anchor tag. Instead, use a button and grab the dropdown value dynamically when it’s clicked:
ADD
Then add this JavaScript:
function executeProcess() {
var dropdown = document.getElementById(‘customer_id’);
var selectedValue = dropdown.value;
if (selectedValue === '') {
alert('Please select a customer ID first');
return;
}
ProcessForm('<?php echo $user['username'];?>', selectedValue);
}
This gives you better control and validation. I’ve used this pattern in my projects - it’s way more reliable than updating anchor href attributes on the fly. The validation prevents empty selections from breaking your ProcessForm function.