2588 posts Put a Donk On It
  • Elite Author: Sold more than $75,000 on Envato Market
  • Sells items exclusively on Envato Market
  • Made it to the Authors' Hall of Fame
  • Has sold $250,000+ on Envato Market
+10 more
ThemeProvince says

Here is my code:


$jadmin("#page_template_select select").change(function () {

    var selected_meta_box = '#' + (($jadmin(this).find("option:selected").attr("role")).replace(/ /g, "_")).toLowerCase();

    $jadmin("#page_template_select select option").each(function () {

        if ($jadmin(this).text() != "Default") {

        var meta_box = $jadmin(this).attr("role").replace(/ /g, "_").toLowerCase();

        $jadmin('div#' + meta_box).hide();

        }

    });

    $jadmin(selected_meta_box).show();

});

Why do I get this error?

Uncaught syntax error, unrecognised expression: #

I don’t get how it can call a string an expression.

Been trying to diagnose for 2 hours and I can’t find a solution, please help!

2122 posts
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Participated in a focus group or interview to improve the user experience on Envato Market
  • Interviewed on an Envato blog
+9 more
revaxarts says
Try

$jadmin("#page_template_select select").change(function () {

    var selected_meta_box = (($jadmin(this).find("option:selected").attr("role")).replace(/ /g, "_")).toLowerCase();

    $jadmin("#page_template_select select option").each(function () {

        if ($jadmin(this).text() != "Default") {

        var meta_box = $jadmin(this).attr("role").replace(/ /g, "_").toLowerCase();

        $jadmin('div#' + meta_box).hide();

        }

    });

    $jadmin('#' + selected_meta_box).show();

});

2588 posts Put a Donk On It
  • Elite Author: Sold more than $75,000 on Envato Market
  • Sells items exclusively on Envato Market
  • Made it to the Authors' Hall of Fame
  • Has sold $250,000+ on Envato Market
+10 more
ThemeProvince says

Didn’t work :(

It only works without the each function like this:


$jadmin("#page_template_select select").change(function () {

    var selected_meta_box = (($jadmin(this).find("option:selected").attr("role")).replace(/ /g, "_")).toLowerCase();

    $jadmin('#' + selected_meta_box).show();

});

So its something wrong with that.

1012 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+6 more
wizylabs says

on which line does that error appear? http://cl.ly/7jZ6 or http://cl.ly/7hyV

3497 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $750,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark Moderator says

Weird, your code seems to work in this fiddle: http://jsfiddle.net/sevenspark/8pYUy/1/

2588 posts Put a Donk On It
  • Elite Author: Sold more than $75,000 on Envato Market
  • Sells items exclusively on Envato Market
  • Made it to the Authors' Hall of Fame
  • Has sold $250,000+ on Envato Market
+10 more
ThemeProvince says

Yesss! I fixed it. There was somehow an extra interation in the each loop. So when jquery tried to hide it, it didnt exist so threw an error. Weird though as this never usually happens, its like my code was haunted by an AS3 compiler.

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by