StealthRT
StealthRT

Reputation: 10542

javascript to php value not sending/adding

I must be tired or something because i am unable to get this line of code to work:

var all = color.val('all');
$('#cssColor" + <?php echo $page ?> + "', parent.document).attr("background-color", all.hex);

I even have a textbox with the page value as well and i try:

var all = color.val('all');
$('#cssColor" + $('#txtPageValue').val() + "', parent.document).attr("background-color", all.hex);

I can not seem to send the page value!

Upvotes: 0

Views: 63

Answers (2)

Mahdi
Mahdi

Reputation: 9417

Try to change this one:

$('#cssColor" + <?php echo $page ?> + "',

to:

$('#cssColor<?php echo $page ?>',

And also, for the second one:

$('#cssColor" + $('#txtPageValue').val() + "',

to:

$('#cssColor' + $('#txtPageValue').val(),

Upvotes: 1

Bryan Gentry
Bryan Gentry

Reputation: 873

I am not sure how you are assigning the all variable, but assuming it is getting assigned correctly, you could rewrite your code something like this to get the value to appear in the right place in your javascript:

<?php echo "<script type='text/javascript'>
        //code somewhere in here should define the color object
        var all = color.val('all')
        $('#cssColor" . $page . "', parent.document).attr('background-color', all.hex);
    </script>"; ?>

This writes the javascript to the document, without breaking the echo function in the middle.

Or, you could do this:

var all = color.val('all');
$('#cssColor'+<?php echo $page; ?>, parent.document).attr('background-color', all.hex);

Upvotes: 1

Related Questions