|
Answer» Hey All am new to html/php Have done a bit of VB in the past,
Now I can't FIND the syntex to pass a var into a style attribute
I have the FOLLOWING CODE
now this is returning the right info have add the function at bottom!
Code: [Select] <script type='text/javascript'> var BGIMG = backgroundpic("<?php echo $store_id; ?>"); </script>
Now I what to pass the above verible into the following code?
Code: [Select] <style type="text/css"> body { background-image: url( BGIMG ); background-repeat:no-repeate; background-attachment:fixed; height:100%; width:100%; background-position:top; } </style> all the above code is PLACE in between and any help you could give would be grate!
Code: [Select] function backgroundpic(store_id) { var ID = store_id; if (id == 'KESW') { var pic = '/inc/adlpic.jpg'; } else if (id == 'YDAR') { var pic = '/inc/darpic.jpg'; } return pic; } Why not skip the JS and just use PHP to output the background image?
Code: [Select]<style type="text/css"> body { background-image: url("<?php echo $store_id; ?>"); background-repeat:no-repeat; background-attachment:fixed; height:100%; width:100%; background-position:top; } </style>
Otherwise you'd have to use JS to output the entire CSS like so.
Code: [Select]<script type="text/javascript"> document.write("<style type='text/css'>\n body\n {\n background-image: url(" + BGIMG + ");\n background-repeat:no-repeat;\n background-attachment:fixed;\n height:100%;\n width:100%;\n background-position:top;\n }\n </style>"); </script> Thanks very much kpac
this is how i solved it
Code: [Select]<script type='text/javascript'> var pic = backgroundpic("<?php echo $store_id; ?>"); document.write("<style type='text/css'>\n body\n {\n background-image: url(" + pic + ");\n background-repeat:repeat;\n background-attachment:fixed;\n height:100%;\n width:100%;\n background-position:top;\n }\n </style>"); </script>
as user selects store id on a previous page and is stored for the session
thanks again!!!
|