Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with scalars 1

Status
Not open for further replies.

safra

Technical User
Joined
Jan 24, 2001
Messages
319
Location
NL
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 &quot;selected&quot; 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 &quot;selected&quot; 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 &quot;selected&quot;?

The scalars look like this (combination form element and option):

@boxes = (&quot;el1&quot;,&quot;el2&quot;,&quot;el3&quot;,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.&quot;option&quot;.$j = &quot;selected&quot;;
            }
	}
}

This is the part I can't get to work:
$selectbox.$i.&quot;option&quot;.$j = &quot;selected&quot;;

I tried all sort of things including 'eval', Nothing worked. How should this line look like?

Regards,

Ron

 
Try this:
Code:
${&quot;selectbox&quot;.$i.&quot;option&quot;.$j} = &quot;selected&quot;;
If the font doesn't show it well, those are CURLY brackets. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Thanks, that worked!

Ron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top