denewey
asked on
I'm getting a conflict on inline styles with php.
I have a script that parses some db data and creates nested lists for a side menu. One function adds each list item to an output variable. When I include an inline style I cannot get the variable written to the screen - don't know if variable is just not created or it's not written. If I don't include the inline style, it writes to the screen just fine.
Here's the function without the inline style. This adds to the variable fine and writes to the screen fine:
And the below code is the same function with the inline style inserted. This will not write to the screen:
Any clue what the conflict is and how I can get around it?
denewey
Here's the function without the inline style. This adds to the variable fine and writes to the screen fine:
function add_nav_level($key,$val,$level_nbr, $end){
global $id_nbrs;
//ADD EACH OF THIS LEVEL TO THE OUTPUT
$id_name = "ul_id" . $key;
$output = "<li><a href='#' class='sub_nav' onClick=\"javascript:jchangeY('" . $id_name . "');\">". $val . "</a>";
$id_nbrs[$level_nbr][] = $id_name;
if ($level_nbr < $end){
$dis_style = "style='display:none;'";
$output .= "<ul id='" . $id_name ."'>";
}
else{
$output .= "</li>";
}
return $output;
}
And the below code is the same function with the inline style inserted. This will not write to the screen:
function add_nav_level($key,$val,$level_nbr, $end){
global $id_nbrs;
//ADD EACH OF THIS LEVEL TO THE OUTPUT
$id_name = "ul_id" . $key;
$output = "<li><a href='#' class='sub_nav' onClick=\"javascript:jchangeY('" . $id_name . "');\">". $val . "</a>";
$id_nbrs[$level_nbr][] = $id_name;
if ($level_nbr < $end){
$dis_style = "style='display:none;'";
$output .= "<ul id='" . $id_name ."' style='display:none;'>";
}
else{
$output .= "</li>";
}
return $output;
}
Any clue what the conflict is and how I can get around it?
denewey
ASKER
I don't want anything to be displayed. I want it to be not displayed so that later with a javaScript function I can display it. But it should be viewable when I view source, and it isn't.
The issue is that when I include that in the output variable, the content of the variable disappears. It's not viewable in source or anywhere.
The issue is that when I include that in the output variable, the content of the variable disappears. It's not viewable in source or anywhere.
I tried it and your function works correctly for me.
However, I would switch your single and double quotes around. Double quotes always cause trouble because they interpret some of the php within them. I would only use double quotes when you have to for the desired effect. In your case there is no need. Switch them to make sure there isn't any conflict like this:
However, I would switch your single and double quotes around. Double quotes always cause trouble because they interpret some of the php within them. I would only use double quotes when you have to for the desired effect. In your case there is no need. Switch them to make sure there isn't any conflict like this:
function add_nav_level($key,$val,$level_nbr, $end){
global $id_nbrs;
//ADD EACH OF THIS LEVEL TO THE OUTPUT
$id_name = 'ul_id' . $key;
$output = '<li><a href="#" class="sub_nav" onClick="javascript:jchangeY(\'' . $id_name . '\');">'. $val . '</a>';
$id_nbrs[$level_nbr][] = $id_name;
if ($level_nbr < $end){
$dis_style = 'style="display:none;"';
$output .= '<ul id="' . $id_name .'" style="display:none;">';
}
else{
$output .= '</li>';
}
return $output;
}
ASKER
Thank you.
It was a problem at work and I won't be back there until Monday, so I'll let you know then if that works for me.
It was a problem at work and I won't be back there until Monday, so I'll let you know then if that works for me.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The problem was in another piece of the code that was not submitted with the original submission.
wit the line
$output .= "<ul id='" . $id_name ."' style='display:none;'>";
style='display:none;'
make that nothing been printed to screen
try changing it to:
$output .= "<ul id='" . $id_name ."' style='display:inline;'>";