Hi,
I have a form that will show the same form with all form elements that have been filled out when certain required fields are not filled in by the user.
Among the form elements are 12 selectboxes with each of them 10 options. I would like to show the correct option for all the select boxes that are filled in by the user. To achieve this, the option tag of the chosen option needs to have 'selected' inside the tag:
<option selected>value</option>
I think the best way to do this is to create a scalar for each option tag and set it to "selected" when 'true' or nothing when 'false'.
<option $scalar>value</option>
I'm experimenting a bit to find the best solution to achieve this. My idea was to create an array of all the form element names. Then run two for-statements to find out the correct option for each form element and set the matching scalar for this option to "selected" but I can't find out how to get all of this to work. especially how can I generate the scalars dynamically and set the correct scalar to "selected"?
The scalars look like this (combination form element and option):
@boxes = ("el1","el2","el3",etc)
$selectbox1option1
$selectbox1option2
etc
$selectbox1option10
$selectbox2option1
etc
This is what I tried:
This is the part I can't get to work:
$selectbox.$i."option".$j = "selected";
I tried all sort of things including 'eval', Nothing worked. How should this line look like?
Regards,
Ron
I have a form that will show the same form with all form elements that have been filled out when certain required fields are not filled in by the user.
Among the form elements are 12 selectboxes with each of them 10 options. I would like to show the correct option for all the select boxes that are filled in by the user. To achieve this, the option tag of the chosen option needs to have 'selected' inside the tag:
<option selected>value</option>
I think the best way to do this is to create a scalar for each option tag and set it to "selected" when 'true' or nothing when 'false'.
<option $scalar>value</option>
I'm experimenting a bit to find the best solution to achieve this. My idea was to create an array of all the form element names. Then run two for-statements to find out the correct option for each form element and set the matching scalar for this option to "selected" but I can't find out how to get all of this to work. especially how can I generate the scalars dynamically and set the correct scalar to "selected"?
The scalars look like this (combination form element and option):
@boxes = ("el1","el2","el3",etc)
$selectbox1option1
$selectbox1option2
etc
$selectbox1option10
$selectbox2option1
etc
This is what I tried:
Code:
for $i (1..12){
for $j (1..10){
if ($input{$boxes[i]} eq $j){
$selectbox.$i."option".$j = "selected";
}
}
}
This is the part I can't get to work:
$selectbox.$i."option".$j = "selected";
I tried all sort of things including 'eval', Nothing worked. How should this line look like?
Regards,
Ron