String Prototype Extensions - Post Your Best!

Apr 27, 2004

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.

View 8 Replies


ADVERTISEMENT

Extended The String Prototype?

Apr 3, 2011

I extended the string prototype with the following.

String.prototype.equalTo = function( str )
{
return this.toLowerCase() === str.toLowerCase();
}

I'm worried about special characters and double byte characters.what I should be looking out for? or doing?

View 2 Replies View Related

Returned Type Of -this- From String.prototype.repeat()

May 10, 2006

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+"";

View 8 Replies View Related

Ajax :: Post A UTF-8 String Via It In Firefox 3?

Jul 15, 2009

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.

Any ideas how I sort this?

View 1 Replies View Related

How To Use GET Or POST Function With Query String

Aug 25, 2010

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.

View 1 Replies View Related

JQuery :: $.post() Is Not Able To Read JSON String?

Jun 12, 2011

In the following post function, alert(data) returns my formatted JSON string:

{"Locations":[
{"__type":"VEMaps.PinData","Title":"1","Description":"Push Pin 1.","Latitude":49.25295,"Longitude":-124.13042},{"__type":"VEMaps.PinData","Title":"2","Description":"Push Pin

[Code]....

View 2 Replies View Related

JQuery :: Adding An Event Handler To A String From A $.post Reponse?

Dec 6, 2011

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?

View 2 Replies View Related

JavaScript Native Extensions

Nov 6, 2007

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....

View 3 Replies View Related

Firefox Extensions Tutorial

Aug 18, 2005

Does anybody know of a good firefox extension tutorial?

Basically I have an XML list of things

<term>bleh</term>
<replacement>blehsky</replacement>

and I want to make the extension replace every occurance of bleh on the webpage with blehsky.

I can handle the javascript to do this, but I don't know where to start in making it into an extension.

View 6 Replies View Related

Search To Return Only .html Extensions

Feb 7, 2006

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?

View 3 Replies View Related

Accessing Private Members In Extensions

Mar 2, 2011

I'm trying to create an extensible class with private members.

Suppose I have the following:

Code:

Obviously, only "y" should be available to instantiations:

Code:

But how can I now extend this class and still access the private properties inside the extension?

Code:

How do I access x there? The someOtherFunction extension is part of the prototype, so it should be in the same scope as someFunction, no?

View 1 Replies View Related

Function To Load Files - With .txt Extensions

Mar 16, 2009

i have a function to load text files.

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.

View 2 Replies View Related

CGI - Frontpage Extensions; Online Forms

Dec 17, 2000

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...

...does this make sense? If not, why not?

View 1 Replies View Related

Difference Between Object.prototype And Function.prototype?

Nov 25, 2011

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

View 5 Replies View Related

How Come Object.prototype Inherits From Function.prototype

Dec 14, 2009

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?

View 24 Replies View Related

Check File Extensions On Multiple Uploads

Sep 10, 2009

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>

View 4 Replies View Related

Passing Parameters To Custom Element Extensions

Feb 12, 2003

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.

View 3 Replies View Related

JQuery :: Ajax Post Success - Run An External Function Outside The Post

Aug 17, 2010

I want to run an external function outside the post.

This is what I have currently.

On success of the post I want to run the setGrandTotal(); function which will do some calculating for me.

View 1 Replies View Related

JQuery :: Use $.post() To Post Array Of Controls?

Oct 11, 2011

How can I post array of controls through &.post() in jQuery??I have some of checkboxs in my page and declare them like this

<input name="mycheckbox[]" "value="myvalue" type="checkbox">

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

$.post('ajax/test.php", {checkbox: $
(
'input[name="mycheckbox"]'
)});

[code]....

View 1 Replies View Related

JQuery :: Post A Form With $.post And Put Results In A Div

Dec 6, 2011

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.

View 3 Replies View Related

Post Action - Form To Post To Another Page?

Oct 19, 2011

[Code]....

how do i cause the form to post to another page? Am I doing it correct? I want this to happen ONLY if validation passes.

View 4 Replies View Related

AJAX :: Cross Domain Post - Post Data From A Form To A Page On Another Domain, Without Leaving The Current Page?

Jan 15, 2010

i need to post data from a form to a page on another domain, without leaving the current page.I am using ASP as a server language.

View 9 Replies View Related

JQuery :: Display The Result Of Ajax Call As Html String And Not Plain String?

Dec 25, 2010

I want to know if there is a way to return ajax call as html value and not plain text, ie all html formatting will be displayed.

My code:

<script src="jquery.js">
<script>
$(function()
{

[Code]....

String returned from webform4.aspx is html formatted but jquery displayed it as plain text. Is that anyway to display it as html string ?

View 3 Replies View Related

Converting Int To String - Variable To Concatenate It As A String To Find An Input Box

Jun 26, 2010

I have a for loop: Code: for( var i = 0; i < aInput.length; i++ ) I want to use this i variable to concatonate it as a string to find an input box

Code:
var j = i;
var qualname = "discountqualifier" + j;
qualname.toString();
if ( inputName == ( qualname ) )
{

Assuming I have a input box named discountqualifier0, discountqualifier1, discountqualifier2 etc...

View 4 Replies View Related

JQuery :: Display Unicode String In Textbox With Ncr String?

Dec 2, 2010

I have some jquery code like this:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1258" />

[code]....

View 1 Replies View Related

JQuery :: String In String An Branch Based On Found?

Oct 18, 2010

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.

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved