JavaScript - Missing Name After . Operator Delete Keyword
Code:
this.delete = function(obj) { .. Is that it ? I can't have delete ? Or can this be written in some other way, including delete ? Similar Tutorialsi was using my JavaScript console as a calculator, and i accidentally used "^" for exponents. the statement did not return a syntax error, but a number, after doing some more ^ operations i can't see the relation between the numbers i use and the answer it gives me. Hello I have a question which has been bugging me for a while now so have decided to ask it on CF. In PHP you can use the '&' symbol as a function operator for example like so. PHP Code: function demoFunc(&$output='') { for($i=1;$i<count(func_get_args());$i++) { $output .= ' '.func_get_arg($i); } $output = trim($output); } As you can see the '&' symbol was used in the argument section to allow the function to be used like this demoFunc($output,'hello','world'); print $output; My question is how can I do this in JavaScript to do the same thing like use the variable used in the function argument section and use it like it would be used in PHP? Thank you - DJCMBear I'm trying to not allow my users to enter in n/a in my form ex... "N/A" "n/A" "na" My code trips the alert every time no matter what is entered in the cell... Why is it doing that? Code: function appliance() { if (document.ComplianceForm.Appliance.value=="n/a" || "N/A" || "n/A" || "N/a") { alert("You cannot enter any variation of n/a in this cell.") } else { return false; }; } I read somewhere (I think from Douglas Crockford) that void is a completely useless operator. What is its actual purpose? Is there anything it's good for? I see lots of javascript:void(0) hyperlinks all over the place. From what I gather, it just disables the link's default behavior...buy why not just make the href="#" or return false from an onClick handler? Can anyone enlighten me? I'm still learning js core using Flanagan's 5th ed. so please bear with me; is the if ("ignore" in arguments.callee) return; below valid or a typeo? Thanks J. Code: function inspect(inspector, title) { var expression, result; // You can use a breakpoint to turn off subsequent breakpoints by // creating a property named "ignore" on this function. if ("ignore" in arguments.callee) return; ....... Hi folks, Any suggestions on how you might achieve the following without using eval()? I've come up a bit short Code: function addOrSubtract(operator) { var a = 10; var b = 5; var answer = eval(a + operator + b); alert(answer); } addOrSubtract('+') // alerts 15 addOrSubtract('-') // alerts 5 Would help me tidy up some code a lot thanks. Code: function Hero() { this.occupation = 'Ninja'; } don't understand the meaning of this line ,this.occupation = 'Ninja'; why it use this keyword. thank you. I'm not sure if this is the right forum, but I'm looking for help with adding a search box to my website. I want to create a keyword search box - one where entering the right keyword(s) will take the visitor DIRECTLY to the page they're looking for, without a results page. And if they don't enter a keyword (in a keyword database?) they're taken to an error page. So, in essence, it's not really a search engine, it's more of a keywords box. Oh, also, some of the keywords will have non alphabetical or numerical characters (like dashes and periods) if that's a concern. Can someone help me with this or point me in the right direction to someone/someplace that can? Thanks.
Hi, I've been searching google endlessly and I've come to the conclusion I'm not using the proper search keywords. I'm trying to create something similar to the banner/button combo you can find he http://www.nba.com and also here, http://home.worldvision.org/?page=nonflash I assume these type of slide show buttons combos use java script and possibly php. If anyone knows the proper name for this type of slide show or can point me to some scripting I would appreciate it. Thanks anotherVar should be -1 if there are no matches, but it doesn't seem to work
PHP Code: var string = "abadafa"; var matches = string.match(/a/gi); //doesn't work with /z/ for example var anotherVar = matches.length || -1; The default operator should return the second value if the first is null or false, and according to PHP Code: try { alert(matches.length); } catch (e){ alert(e); //alerts null } it's null. fyi: http://helephant.com/2008/12/javascr...ault-operator/ What's going on? If number is more than 24 digits, modulus operator is not giving correct output here attached sample code [code]<script type="text/javascript"> var a=10000000000000000000000.0; var b=10.0; var c=a % b; alert("c"+c); </script>[code] please tel me solution Hi everybody, I have an search form and I'm handling it with .htaccess like this: RewriteRule ^(.*)/search/(.*) /search.php?lang=$1&keyword=$2 The problem, i can't call the right URL from front-end. I have an search form with get and if i search something the url going to like this: domain.com/en/search/?keyword=test 404.. But if i type the URL manually like this: domain.com/en/search/test Than it's working well. So, I need some js code to put search keyword in the right form so i can cancel the <form>. Can somebody help me to write this code? Or any other ideas are welcome. Hi, I'm Jon. First of all excuse me if I posted this thread in the wrong forum, I really have no clue where to put this but I've had some minor experience with js so I hope it can be solved this way. I check websites and/or keywords in googles Keyword Tool External as a free service for some of my clients. The thing is that more and more clients like this service and it's becoming very time-consuming for me to do this for all of them. Is there a way to let my clients fill in the keywords or url they like researched in a form on my website, then let those words be researched and return a specified number of results in a pdf or something? My biggest concern is the captcha code. If I can't find a way to partially or fully automate this process, I'll be forced to either charge for or completely give up this service. Can anyone help me with some kind of solution? Thanks in advance. Jon tested this only on FF. Code: target = this.parentNode.parentNode.getElementsByClassName('help')[0]; target.style.display = (target.style.display=='none')?'inline':'none'; -->Error: target.style is undefined In next two codes what is red is different, all the rest as above. Code: var target = this.parentNode.parentNode.getElementsByClassName('help')[0]; target.style.display = (target.style.display=='none')?'inline':'none'; --> works. Code: xxx = this.parentNode.parentNode.getElementsByClassName('help')[0]; xxx .style.display = ( xxx .style.display=='none')?'inline':'none'; --> works. Why is that ? I'm looking at building an interactive desktop gadget for our company computers that functions similar to Clippy (less annoying though). The idea is for users to be able to type in keywords or questions and have the gadget present links to pages on our intranet. So similar to a search engine but more focused on answering questions as opposed to just returning a hundred results. I've got a moderate understanding of java so I know I could do something like IF "Textbox" EQUALS "Keyword" THEN DO "THAT". Need a little more sophistication though, it should be able to accept multiple keywords and weigh the search results accordingly. I'm sort of picturing an updatable XML table like this: KEYWORD This is the result KEYWORD This is the result Or an array in a separate .js file. Maybe there's a better way than that actually but it's what I know. Has anyone got some advice on this? Thanks. Hello all, Sorry if this may seem like a silly question, I have searched but not really to sure how to word what I am searching for as I don't know if I am going the right way around it! Basically, I am looking to insert a keyword in to a javascript alert box when someone visits my website, so say they came from codingforums.com, it would say "Welcome, CodingForums.com Visitor". My keyword will be passed from the ad platform I am working with and shows up correctly in the tracking, so I'd imagine it's just a case of having the snippet of code for it to show in the alert, correct? If there is no keyword, I would just like it to say "Welcome Visitor" or something. How do I go about this? Thank you in advance for any help. this is my javascript code: Code: var aaa, aab; aaa = choo.chooserver0.checked; aab = choo.chooserver1.checked; k=(aaa==true)?0:(aab==true)?1:(aaa=true&&aab==true)? 'b2' : false ; now when the checkbox with id chooserver0 is checked, it sets k's value to 0, and when checkbox with id chooserver1 is checked it sets its value to 1, but when both are checked it must set value to b2, but it sets value to 0, why? and when i write it as: Code: var aaa, aab; aaa = choo.chooserver0.checked; aab = choo.chooserver1.checked; k=(aaa=true&&aab==true)? 'b2' :(aaa==true)?0:(aab==true)?1: false ; when box 1 is checked, it sets k= false, when box2 is checked it sets k= 'b2' and when both are checked it sets k = 'b2'... why is code doing so? I am confused about what the return keyword is actually returning when returning an object, a primitive, or a function. My confusion is compounded by the fact that I'm not sure if a function is an object or not. According to the book JavaScript Programmer Reference it is: "All functions in JavaScript are first class objects , meaning they can be passed around like any other object reference. In fact, regardless of how they are created, functions are instances of a global object named (aptly) Function." However, someone else states that a function is not an object. An object is a set of primitives and references. A function is executable code. Functions become objects through the use of the new operator. Yet, in the book I mentioned, it says you don't need the new keyword to execute the function as an object, as it already inherits from the object Function when the function keyword is used: Code: function functionName([argname1 [, ...[, argnameN]]]) { statements; } So there's one source of contradiction. Now the bigger issue is what is going on when the return keyword is used. Notice the Validation() function returns an object as its last expression. This technique is common, where you return an object which contains functions in form of object notation. I believe this is done so that we create a closure so that when the intepreter exits the Validation() method, since we created a closure by returning an object, which contains the inner functions addRule and getRule, the local variables of Validation() are not destroyed, given that we can reference them through the two inner functions that make use of the local variables of the outer function. So when we use the return keyword on an object literal, and then exit the function, when we call one of the inner functions as we do later: Code: var rule = $.Validation.getRule(types[type]); essentially getRule() is called, passes an argument, which is received by the inner function as parameter we call name: Code: getRule : function(name) { return rules[name]; } First, note that the return {} is written in object notation, therefore making getRule a local variable and, thus, private function only accessible through the namespace of Validation(). Validation() declares the rules local variable and because of the closure, we can access the rules local variable through the getRule() inner function. *****Here's the part that really thows me off. We return rules[name]. So let's say name is equal to email. This is an associative array so email (held in name) is a property of rules. So here we return the object's property: Code: return rules[name]; And then assign it to a local variable called rule: Code: var rule = $.Validation.getRule(types[type]); So when we return an object rules[name], do we return a reference to an object or a value? In other words, by returning rules[name], where name is equal to email, are we then returning a reference to the following object literal: Code: email : { check: function(value) { if(value) return testPattern(value,".+@.+\..+"); return true; }, msg : "Enter a valid e-mail address." } And if we are returning a reference, by returning a reference, are we essentially pointing to this object when we assign it to rule? In other words, the variable rule is just pointing to the object literal? And is that the reason we can then access the check function or msg local variable through rule using dot notation, because rule points to the email object literal? Now the ultimate brain twist for me is that if a function is an object, then why when return a function, it returns a value, such as a boolean, if an object only returns a reference and not the value? Code: //Validation is a local variable as it is in a self-executing anonymous function. The purpose of the said anonymous function is to pass the jQuery object as a parameter $ so the $() function will be in scope of the anonymous function and not interfere with other libraries that make use of the same function technique - in the global scope. (function($) { var rules = { email : { check: function(value) { if(value) return testPattern(value,".+@.+\..+"); return true; }, msg : "Enter a valid e-mail address." }, url : { check : function(value) { if(value) return testPattern(value,"https?://(.+\.)+.{2,4}(/.*)?"); return true; }, msg : "Enter a valid URL." }, required : { check: function(value) { if(value) return true; else return false; }, msg : "This field is required." } } var testPattern = function(value, pattern) { var regExp = new RegExp("^"+pattern+"$",""); return regExp.test(value); //The test() method is built into javascript } return { addRule : function(name, rule) { rules[name] = rule; }, getRule : function(name) { return rules[name]; } } } /* Form factory */ var Form = function(form) { var fields = []; $(form[0].elements).each(function() { var field = $(this); if(field.attr('validation') !== undefined) { fields.push(new Field(field)); } }); this.fields = fields; } Form.prototype = { validate : function() { for(field in this.fields) { this.fields[field].validate(); } }, isValid : function() { for(field in this.fields) { if(!this.fields[field].valid) { this.fields[field].field.focus(); return false; } } return true; } } /* Field factory */ var Field = function(field) { this.field = field; this.valid = false; this.attach("change"); } Field.prototype = { attach : function(event) { var obj = this; if(event == "change") { obj.field.bind("change",function() { return obj.validate(); }); } if(event == "keyup") { obj.field.bind("keyup",function(e) { return obj.validate(); }); } }, validate : function() { var obj = this, field = obj.field, errorClass = "errorlist", errorlist = $(document.createElement("ul")).addClass(errorClass), types = field.attr("validation").split(" "), container = field.parent(), errors = []; field.next(".errorlist").remove(); for (var type in types) { var rule = $.Validation.getRule(types[type]); if(!rule.check(field.val())) { container.addClass("error"); errors.push(rule.msg); } } if(errors.length) { obj.field.unbind("keyup") obj.attach("keyup"); field.after(errorlist.empty()); for(error in errors) { errorlist.append("<li>"+ errors[error] +"</li>"); } obj.valid = false; } else { errorlist.remove(); container.removeClass("error"); obj.valid = true; } } } /* Validation extends jQuery prototype */ $.extend($.fn, { validation : function() { var validator = new Form($(this)); $.data($(this)[0], 'validator', validator); $(this).bind("submit", function(e) { validator.validate(); if(!validator.isValid()) { e.preventDefault(); } }); }, validate : function() { var validator = $.data($(this)[0], 'validator'); validator.validate(); return validator.isValid(); } }); $.Validation = new Validation(); })(jQuery); Thanks for any response. Hi I need to develop a simple keyword search in external html files(having traversing in directories ability). Is this possible? (in this case php can be used) Please guide me Thanks [Okay, so I just wrote a simple code to try and figure out how javascript works and I can't even get this to work. What am I missing?] <html> <head> <script type="text/javascript"> var c=a+b; function displaymessage() { alert("The answer is " + c) } </script> </head> <body> <form> <p>Enter the first number <input type="text" name="a"></p> <p>Enter the second number <input type="text" name="b"></p> <input type="button" value="Enter" onclick="displaymessage()"/> </form> </body> </html> |