So i’m terrible are js, and i’m trying to get a jquery script, to onblur check if the text box has content, and if it does then proceed with the script, this is what i have
<script type="text/javascript">
$(document).ready(function() {
$("#embed").blur(function (){
$("#embed").val().length > 0){
$("#fade").fadeIn(1000);olink = $("#embed").val();
$("#oembed").oembed(olink, {
embedMethod: "append",
maxWidth: 300,
maxHeight: 150
});
});
}
});
</script>
but i’m getting a syntax error(dreamweaver) on the line that reads
$(“#embed”).val().length > 0){
any suggestions would be great… thanks
This is what your code should look like (in my opinion, of course), properly formatted:
What was wrong with the code you posted, other than the messy cluster of confusion? Your
if()wasn’t… there. You leftif(out:Can you see it? Kinda hard to differentiate those three lines. Now look at the code above, which…
var $embed = $("#embed")).varto declare all variables, separated by a,so they’re all local; also…olinka proper non-global-scoped variable (and hey, still works due to closures, how nifty).oembedobject (which I created from that{}being passed as an argument) into a proper variable, cleaning the code up and also caching it.I think it’s legitimately easier to read and spot problems if you take care when formatting your code and decide to use best practices like caching and non-global variables. The
if(was the immediate problem, but the code over all was in need of some attention and a little lovin’ kindness.