Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript working in jsfiddle but not in the browser.

  • This topic is empty.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #187144
    mlotfi
    Participant

    Hi,

    I am trying the jqueryui code for Dialog modal form from here :
    http://jqueryui.com/dialog/#modal-form

    I tried to add a drop down menu, my code is working in jsfiddle but not in the browser.

    function isEmpty(str) {
    if (str === "")
    {
    $('.enva').addClass( "ui-state-error" );
    updateTips("You must select an environment");
    return false;
    }
    else
    return true
    }
    <code></code>

    My jsfiddle :
    http://jsfiddle.net/mlotfi/8kL3ndxd/6/

    Thanks, your help is appreciated

    #187146
    __
    Participant

    my code is working in jsfiddle but not in the browser.

    How are you viewing the jsfiddle website, if not with a browser?

    ; )

    But seriously: how does your markup+code differ from that which you put in jsfiddle? Is jsfiddle loading any assets for you (e.g., jQuery)? is jsfiddle running your code on DOM ready, and did you make sure to do the same?

    Also, I know the formatting is bad here on the forums, but it looks like the code you posted is missing an opening bracket (right after else), and a semicolon (right after return true).

    #187148
    mlotfi
    Participant

    you right, the code is missing the semicolon right after return true, but I did not see where to put the missing bracket, because else has only one to be executed.

    #187151
    __
    Participant

    ah, I see what you mean. I always use brackets, even when they are not technically required. This is generally a good idea, and I highly recommend it. It makes mistakes harder (or, at least, easier to notice).

    Did you find any ways in which your code differed from jsfiddle?

    #187188
    mlotfi
    Participant

    Here is my local js code :

    http://pastebin.com/fYmPFZHd

    checkEmpty(str) always return false (env always === “”).

    I just noticed that when I change jsfiddle running code on DOM ready, it does not work, but it works when it is onLoad.

    #187197
    __
    Participant

    Here is my local js code

    okay…? That’s not what I asked you.

    Did you find any ways in which your code differed from jsfiddle?

    This is the important part. Obviously, something is different, as it works one way and not the other. The items I suggested in my first post are very likely culprits. That’s why I mentioned them: they’re the things you might check first:

    Is jsfiddle loading any assets for you (e.g., jQuery)?
    Is jsfiddle running your code on DOM ready, and did you make sure to do the same?

    #187198
    mlotfi
    Participant

    Yes jsfiddle is loading external resources (jqueries ui and min).

    I just noticed that when I change jsfiddle running code on DOM ready, it does not work, but it works when it is onLoad.

    #187206
    __
    Participant

    Yes jsfiddle is loading external resources (jqueries ui and min).

    So, does your “local” version make sure to load these resources, and in the proper order?

    I just noticed that when I change jsfiddle running code on DOM ready, it does not work, but it works when it is onLoad.

    Good! So that means when your script runs is having an effect. Is your local version running onload, or on domready? some other time?

    #187207
    mlotfi
    Participant

    I have already posted my code :
    http://pastebin.com/fYmPFZHd

    my js start with :
    $(function($){

    #187211
    __
    Participant

    Are we talking about the env var under the comment “// start modal”? which is expected to hold the #env element? If so, have you confirmed that it is finding that element? and that it has a value? what does the alert you put inside the checkEmpty function show?

    I’m sorry if this is frustrating, but I can’t magically solve your problem without first finding out the state of your DOM. That fact that it works in jsfiddle (which tends to manages such things for you), and that you can “break” the fiddle by changing it to run onDOMready, are good indicators that the DOM on your local page isn’t in the same state and that $('#env') is simply not finding anything (or, the “right” thing—e.g., if your local page has a typo somewhere, or multiple #env elements).

    #187212
    mlotfi
    Participant

    I found the solution, it was my mistake, I had two inputs that has the same id env.

    #187237
    __
    Participant

    Glad you found it. Sounded like something like that.

Viewing 12 posts - 1 through 12 (of 12 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.