I couldn't find a single thread with the creme de la creme of String prototype extension methods, so I figured I'd start one. Here we go!
String.prototype.lTrim = function () {
return this.replace(/^s+/gm, "");
}
String.prototype.rTrim = function () {
return this.replace(/s+$/gm, "");
}
String.prototype.trim = function () {
return this.rTrim().lTrim();
}Obviously, this one's easy to understand. I'm using multi-line mode so as only to get rid of spaces and tabs before and after words. Single-line mode would replace any newline/carriage return characters as well.
String.prototype.capitalize = function () {
return this.replace(/[a-z]/g, function (str, n) { return str.toUpperCase(); });
}
String.prototype.toCamelCase = function () {
return this.replace(/s[a-z]/g, function (str, n) { return str.toUpperCase(); });
}
String.prototype.unCamelCase = function () {
return this.replace(/[A-Z]/g, function (str, n) { return " " + str.toUpperCase(); });
}This is something I needed today, to turn a camelCased variable value into its Header Format. While I was at it, I wrote the un-do-er.
I wrote a .repeat(n) function for strings which seemed to work fine:
String.prototype.repeat = function(n) { // repeats the string n times if (n<1) return ""; if (n<2) return this; for (var aStr = [this];--n>0;) aStr.push(aStr[0]); return aStr.join(""); }
Only I was a little surprised to get "object" (instead of "string") when I tried: alert (typeof ("x".repeat(1)));
I fixed this by modifying ... if (n<2) return this+"";
I'm trying to post some xml to the server via ajax that contains utf characters. (�, �, etc...)
IE presented no problems, but firefox insists on mangling the chars.
Here's what I'm currently trying. code...
If I look at what is posted using the tamperdata plug in I can see that the charset specified in the header is utf-8. But the chars in the posted data are garbled.
I am new to Javascript and i'm currently building a site that entails a 'quiz' part where the client selects an option from a radio button. Then they move on to a different page, and so on and so on until a results page where the correct number of questions answered are made into a percentage.I understand that you can use the GET or POST to pass this into the query string and then extract the answers from the query string but I am having trouble implementing this.
I have a basic HTML form with a button that submits the form via jQuery's $.post to a processor. That processor returns the identical form, including any errors below any of the elements e.g. input, textarea, etc. The response also has a new submit button to submit the form once more, however, because I'm retrieving a giant string with HTML elements and because jQuery already loaded, that new submit button doesn't do anything. How can I parse jQuery's response for that button and assign a handler so that when the button is pushed, it submits the form again?
I'd like to announce release 1.0.7 of JNEXT (JavaScript Native Extensions). JNEXT is an open source framework for securely accessing the full range of native OS resources (files, databases, sockets etc.) by using JavaScript from within a Web Page. It is light weight, cross platform, cross browser and designed with simplicity in mind....
I"m trying to do a search on a folder that contains both word docs and html pages. I want the search to only return back the html pages. Does anyone know the code for that?
function load(n){textfile=n;if(n.indexOf("#")!=-1){theleft=n.indexOf("#")+1;textfile=(n.substring(theleft))} document.mycall.load(textfile+'.txt');origString=textfile;
and it only loads a files with .txt extensions. how to change this function to load files with .doc and .nfo extensions also.
I have been using Frontpage to design web sites and know that online-forms can be created using Frontpage, but the host must have Frontpage Server Extensions installed...
...I was wondering if the online forms were simply CGI scripts??
If so, could i not get DreamWeaver Ultra Dev and write the CGI scripts in there? - I think DreamWeaver is capable of this?
Therefore, if a server supported CGI scripts and i had to pay extra for FRONTPAGE EXT. then i could bypass this problem by using CGI scripts...
According to ECMAScript, the root of the prototype chain is Object.Prototype. Each object has an internal property [[Prototype]] that could be another object or NULL.... However, it also says that every function has the Function prototype object: Function.Prototype, it confused me, because a function is an object, for a function object, what is its function prototype and object prototype..For example:
var x = function (n) {return n+1;};
what is the relationships of x, Object.Prototype and Function.Prototype
I am trying to get to the bottom of javascript object, prototypes etc. I have a fairly good grasp of it, but I get confused the closer I get to the base object.prototype. FIrst of all, I was under the impression that all objects descend directly from Object. But some objects (like Array) seem to inherit properties and methods from the function.prototype. So does this mean that the chain is like this:
object -- function -- array Second, I noticed (on the mozilla javascript reference site that object.prototype inherits properties and methods from function.prototype and vice versa!? How can this be? I must be missing something important about understanding the chain?
Script works on the first attachment but not the other two? <script type="text/javascript" language="JavaScript"><!-- function ExtensionsOkay() { var extension = new Array(); var fieldvalue = new Array(); fieldvalue[0] = document.customApp.attachment_1.value; fieldvalue[1] = document.customApp.attachment_2.value; fieldvalue[2] = document.customApp.attachment_3.value; extension[0] = ".doc"; extension[1] = ".docx"; extension[2] = ".txt"; extension[3] = ".pdf";
// No other customization needed. for(var f = 0; f < fieldvalue.length; f++) { var thisext = fieldvalue[f].substr(fieldvalue[f].lastIndexOf('.')); for(var i = 0; i < extension.length; i++) { if(thisext == extension[i]) { return true; }} alert("Your upload field " + f + " contains an unapproved file name."); return false; }} //--></script>
When introducing custom functionality to HTML elements we either use existing attributes to pass configuration parameters (like beetle's fValidate (http://www.peterbailey.net/fValidate/)) or invent our own (like my Tooltips (http://www.vladdy.net/webdesign/ToolTips.html)). While this method is ok for small amount of configuration information, it is not that flexible (you need to edit DTD) and becomes combersome when large amount of configuration parameters is needed.
I figured a more convinient way is to use a CSS like string to pass configuration parameters: <div myextension="parameter1: value1; parameter2-subparameter1: value2.1; parameter2-subparameter2: value2.2"> </div>
Then initialization routine would contain: if(myExtensionParameters = divElement.getAttribute('myExtension')) divElement.myExtension = new myExtensionObject(divElement,myExtensionParameters);
Definition of possible parameters and their values can be done using an array of regular expressions: myExtensionParamDefenitions = new Array(); myExtensionParamDefenitions['choiceparameter'] = /^s*(value1a|value1b|value1c)s*$/; myExtensionParamDefenitions['stringparameter'] = /^s*(w+)s*$/; myExtensionParamDefenitions['integerparameter'] = /^s*(d+)s*$/;
Constructor for the myExtensionObject would containd a parseParameters function: function myExtensionObject(divElement,myExtensionParameters) { this.params=new Array(); parseParameters(this.params,myExtensionParamDefenitions,myExtensionParameters); //Verify parameter initialization, if you like str='' for(e in this.params) str+= e + ': ' + this.params[e] + ' ' alert(str); //Do whatever you have to do... }
Function parseParameters has the following code: function parseParameters(object,definitions,parameters) { paramEntries = parameters.split(''); for(var i=0; i<paramEntries.length; i++) { paramEntry = paramEntries[i].split(':'); if(paramEntry.length == 2) { paramName = paramEntry[0].replace(/^s*([w-]+)s*$/,'$1'); if(definitions[paramName]) { res = definitions[paramName].exec(paramEntry[1]); if(res[1]) object[convertCSSName(paramName)] = res[1]; } } } }
Where convertCSSName function converts CSS type name (background-image) to javascript name (backgroundImage) function convertCSSName(cssName) { sn = cssName.split('-'); rs = sn[0]; for(var i=1; i<sn.length; i++) rs += sn[i].replace(/^(w)(w*)$/,function(str,p1,p2,offset,s){return p1.toUpperCase() + p2;}) return rs; }
As a result you have params array of myExtensionObject object populated with validated entries. Changes and expansion is done by simply editing myExtensionParamDefenitions array.
PS: The functions are coded more for clarity rather than for brevity - I'm certain there are ways to improve the implementation.
I can get it works if I using <form> tag with an action="post" and a submit button to post to another php page by using this statement to get all controls in receiver's page _GET['mycheckbox'];I have tried
I just started using jQuery, but i can't get it working. On the index.php page I want a search form, that post's to search.php. Following next, I want that the html of search.php (which will only be a table with the results), is show into the 'results' div in the index.php.
This is the code im using:
<script type="text/javascript"> /* attach a submit handler to the form */ $(document).ready(function(){ alert("Ok - 1");
[Code].....
The alert's are for debugging, but none of them show's up.
I need a simple, quick and efficient way to logically branch if I find a string is contained in another string in jquery Most other languages this can be resolved in one or two lines and it would be readable.