0

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!

10
  • What are you trying to do with var all = color.val('all'); ?? Commented Sep 30, 2012 at 4:49
  • @hsalama: Its a hex color value. It comes formatted like #54ff65 etc etc Commented Sep 30, 2012 at 4:50
  • 1
    I'm pretty sure this code snippet is riddled with parse errors... Commented Sep 30, 2012 at 4:52
  • 1
    Is this giving you a php error? Because it should. Commented Sep 30, 2012 at 4:52
  • 2
    ... for example $('#cssColor" +... why do you open with single quotes and finish with double quotes? Commented Sep 30, 2012 at 4:52

2 Answers 2

1

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(),
Sign up to request clarification or add additional context in comments.

Comments

1

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.