Home › Forums › JavaScript › working in jsfiddle but not in the browser.
- This topic is empty.
-
AuthorPosts
-
October 27, 2014 at 6:04 pm #187144mlotfiParticipant
Hi,
I am trying the jqueryui code for Dialog modal form from here :
http://jqueryui.com/dialog/#modal-formI 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
October 27, 2014 at 6:12 pm #187146__Participantmy 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 afterreturn true
).October 27, 2014 at 6:33 pm #187148mlotfiParticipantyou 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.
October 27, 2014 at 7:54 pm #187151__Participantah, 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?
October 28, 2014 at 9:09 am #187188mlotfiParticipantHere is my local js code :
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.
October 28, 2014 at 9:41 am #187197__ParticipantHere 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?October 28, 2014 at 9:47 am #187198mlotfiParticipantYes 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.
October 28, 2014 at 10:04 am #187206__ParticipantYes 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?
October 28, 2014 at 10:07 am #187207mlotfiParticipantI have already posted my code :
http://pastebin.com/fYmPFZHdmy js start with :
$(function($){October 28, 2014 at 10:46 am #187211__ParticipantAre 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 thecheckEmpty
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).October 28, 2014 at 11:10 am #187212mlotfiParticipantI found the solution, it was my mistake, I had two inputs that has the same id env.
October 28, 2014 at 2:27 pm #187237__ParticipantGlad you found it. Sounded like something like that.
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.