/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] calling a variable –from a variable — in a function

Lousy Title I know, but couldn’t think how better to phrase it.
Please bare with me.

I’m trying to call the correct dropdown options from $comDiv1 and $dropDiv_a1 into the following function
“make_comboBoxDiv($cbxType,$num)” based on $cbxType variable.(See comments lines 45,51,63-65).

If I enter EITHER the variable $comDiv1; or $dropDiv_a1; on line 63, the select option values from either, populate into BOTH the resulting fields, however if I enter the $options; variable on line 63, the result is that instead getting the appropriate OPTION VALUES from $comDiv1; and $dropDiv_a1; in comDiv1 and dropDiv_a1 respectively, I get instead simply the STRINGS “$comDiv” and “$dropDiv_a1” respectively returned in the source.

Please, what am I doing wrong here?

[code=php]<script>
// quick browser tests
var ie5 = (document.all && document.getElementById) ? true : false;
function show(sw,obj) {
// show/hide divs
if (sw && ie5) document.all[obj].style.display = ‘block’;
if (!sw && ie5) document.all[obj].style.display = ‘none’;
}
function popTextField(fieldName,fieldValue){
document.getElementById(fieldName).value=fieldValue;
}
</script>

<style>
<!–
.myLayersClass { position: relative; top:0px; left:10px; display: none;style=’z-index: 99′ }
–>
</style>
<body>
<?php
$pgCode=’a’;//(alphaKey)
global $pgCode;
function make_comboBoxDiv($cbxType,$num){
$comDiv1=”
<option>Select Option</option>
<option value=’Red’>Red</option>
<option value=’Green’>Green</option>
<option value=’Blue’>Blue</option>
“;
$dropDiv_a1=”
<option>Select Option</option>
<option value=’Cyan’>Cyan</option>
<option value=’Magenta’>Magenta</option>
<option value=’Yellow’>Yellow</option>
“;
if($cbxType==’1′){
$textName=”comments_”.$num;
$selDiv=”comDiv”.$num;
$selName=”comSel_”.$num;
$options=”$”.$selDiv;//echos dropDiv_a1
}
else if($cbxType==’2′){
$textName=”drop_”.$pgCode.$num;
$selDiv=”dropDiv_”.$pgCode.$num;
$selName=”dropSel_”.$pgCode.$num;
$options=”$”.$selDiv;//echos comDiv1
}
$div=”<div>
<input type=’text’ name=’$textName’ id=’$textName’
onFocus=”show(true,’$selDiv’);”
onblur=”ff=’$selDiv’; sTo=setTimeout(‘show(false,ff)’,5);//allow switch focus to <select> below”>
<div id=’$selDiv’ class=’myLayersClass’>
<select name=’$selName’ id=’$selName’
onFocus=’clearTimeout(sTo);’
onBlur=’show(false,”$selDiv”);’
onchange=”popTextField(‘$textName’,this.value);show(false,’$selDiv’);” >
“;
$div .= $comDiv1;//this works
//$div .= $dropDiv_a1;//this works
//$div .= $options;//this doesn’t work
$div .= “</select>
</div>
</div>”;
echo”$div”;
}
?>
<table style=’table-layout: fixed;’ >
<tr height=”25″>
<td ><?php make_comboBoxDiv(2,1);?></td>
<td ></td>
<td ></td>
<td ></td>
</tr>
<tr >
<td ><?php make_comboBoxDiv(1,1);?></td>
<td ></td>
<td ></td>
<td ></td>
</tr>
</table>

</body>[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@tjmcdauthorNov 20.2007 — Changed this line:[code=php]$options="$".$selDiv;
// to
$options=$$selDiv;[/code]
×

Success!

Help @tjmcd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...