How to store css code in a php variable to be used with Javascript -


i'm developing product , 1 of options provide ability copy , paste own css gradient code reliable sources such colorzilla.

how can save such code in php object (for use default settings) , output within javascript/jquery code while retaining programming sense of code. have tried using "addslashes()" no avail.

at moment, i've got:

$default_options = array(         'header_wrap_grad'          =>          '                                             background: rgb(169,3,41); /* old browsers */                                             background: -moz-linear-gradient(top,  rgba(169,3,41,1) 0%, rgba(143,2,34,1) 44%, rgba(109,0,25,1) 100%); /* ff3.6+ */                                             background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(169,3,41,1)), color-stop(44%,rgba(143,2,34,1)), color-stop(100%,rgba(109,0,25,1))); /* chrome,safari4+ */                                             background: -webkit-linear-gradient(top,  rgba(169,3,41,1) 0%,rgba(143,2,34,1) 44%,rgba(109,0,25,1) 100%); /* chrome10+,safari5.1+ */                                             background: -o-linear-gradient(top,  rgba(169,3,41,1) 0%,rgba(143,2,34,1) 44%,rgba(109,0,25,1) 100%); /* opera 11.10+ */                                             background: -ms-linear-gradient(top,  rgba(169,3,41,1) 0%,rgba(143,2,34,1) 44%,rgba(109,0,25,1) 100%); /* ie10+ */                                             background: linear-gradient(top,  rgba(169,3,41,1) 0%,rgba(143,2,34,1) 44%,rgba(109,0,25,1) 100%); /* w3c */                                             filter: progid:dximagetransform.microsoft.gradient( startcolorstr=\'#a90329\', endcolorstr=\'#6d0019\',gradienttype=0 ); /* ie6-9 */                                             ', 

then later on within tags ive got :

$('#header-wrap-grad').attr('value', '<?php echo addslashes($default_options['header_wrap_grad']); ?>'); 

with #header-wrap-grad being textarea i'm trying populate css code variable. however, isn't working. im getting error "unexpected token :" when try echo out variable.

can point me in right direction please?

thanks.

you're creating javascript string, use json_encode (and no surrounding quotes):

$('#header-wrap-grad').attr('value', <?php echo json_encode($default_options['header_wrap_grad']); ?>); 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -