Substring Syntax In Javascript

Jul 23, 2005

Trying to debug someone else's javascript code. There is a line that

looks like this:

req = req.substring(req.length-2, req.length);

From what I can gather in their comments, they want to capture the last two characters of the string "req".

I'm guessing that the above line won't do that, and they want to change it to

req = req.substring(req.length-1, 2);

In other words, the parameters are starting position, and length. Is that correct?

View 6 Replies


ADVERTISEMENT

Getting A Substring In Javascript

Feb 17, 2006

I have the following string:

http://www.myurl.com/folderbit/moer.../sdaf/01354.jpg

and I want to extract the filename from it.

Do you know how to do this, if I don't know the exact names of the folders,
etc...

View 3 Replies View Related

Javascript Class Syntax

Apr 3, 2006

I discovered this syntax on the google example of a client to their web
service.

function PagClass()
{
this.init();
}

PagClass.prototype = {

init : function() {
this.m_bInited = true;
this.m_nTotalRows = 0;
this.m_nFirstRowNum = 0;
this.m_nRowsPerPage = 0;
this.m_nNumPages = 0;
this.m_nReportid = 0;
this.m_nResultNumStart = 0;
this.m_strStart = "";
},

foo: function() {...},
bar: function() {...}
}

This seems like a very elegant way to create classes in javascript,
gives you a constructor and lists methods as comma separated
properties.

My colleague is suspicious that there may be excessive runtime overhead
associated with the prototype, property list way of doing this.
Anybody know for sure?

View 1 Replies View Related

Perl Cgi And Javascript Syntax Please

Jul 30, 2009

I just need someone to tell me what the proper syntax is for calling a perl sub from another perl sub.. in trying to use onClick to call a sub in Htmlform() .. but its not working... the cgi works fine.. the mySql parts work fine.. more specificallyprint start_html(-title=>'Lab 6',-scrip=>{-language=>'PerlScript', src=>'mySqlProg.cgi'});i dont know if the above is the corect syntax in relation to thisprint "<button type='button' value='view' onclick='show_entries();'>Show Table Values</button>";

#!/usr/bin/perl
use strict; use warnings;
use CGI qw/:all/;

[code]....

View 4 Replies View Related

Online Javascript Syntax Checker

Jul 2, 2002

I have a whole heap of Javascript that I want to compress (by removing line breaks etc). When laid out with line breaks, all works fine. When compressed ... BANG!

I suspect that there is a semi-colon missing somewhere which is only breaking when the return is removed. However, I'd like to run the whole block of javascript through an online validator instead of straining my eyes trying to locate the piece of the script at fault.

Is there such a thing? When I search for 'Javascript validator', I get a whole heap of links to using javascript to validate forms and such like!

View 1 Replies View Related

Substring?

Jul 20, 2005

How do i find the value next to width= (500)
in:

'"../graphics/press/012.jpg" width=500 height=339'

View 6 Replies View Related

Substring(1,2)??

Oct 3, 2003

what does that do?? and is there a javascript manual out there that I can look up function in?

View 8 Replies View Related

Smart Substring

Sep 9, 2007

If I have the following variable which contains the drop down menu for list of card numebrs:

var abc='<option value="1234567890123456">1234567890123456</option><option value="0987654321987654">0987654321987654</option><option value="0147852369014785">0147852369014785</option>'

How can I pass this variable to a function and mask only the dispalyed card number? i.e. to have the following result:

<option value="1234567890123456">1234XXXXXXXX3456</option><option value="0987654321987654">0987XXXXXXXX7654</option><option value="0147852369014785">0147XXXXXXXX4785</option>

Note: the number of options in the drop down menu may varry, in this example its only 3 options, it might be more or less, this is why I called it "Smart Substring".

View 1 Replies View Related

Replacing A Varying Substring With Itself Plus

Jul 23, 2005

I'd like to globally replace a substring specified by a regular
expression with itself along with some additional characters.
example:

var oldString = 'asdf BRACKETTHISasdfsdf sd asdBRACKETTHISasdf asd'

var newString =
oldString.replace(/sw*BRACKETTHISw*/g, '<' + ?some expression that
accesses current match? + '>' )

And newString winds up as:
'asdf <BRACKETTHISasdfsdf> sd <asdBRACKETTHISasdf>
asd'

Is there a way to do this, or do I have to use other methods?

View 1 Replies View Related

Regular Expression For Substring?

Jul 7, 2010

what will be the regular expression for this line:

Code JavaScript:
var id = $(this).attr("href").substring( $(this).attr("href").lastIndexOf('#'), $(this).attr("href").length);

Basically it gets the string after # in href attribute of clicked anchor tag.

View 3 Replies View Related

Retrieve Substring From The Above URLs

Mar 8, 2011

I have URLs as follows. [URL] I need a function which can retrieve substring from the above URLs. The substring should be upto the 2nd occurence of '/' as follows. [URL]

View 2 Replies View Related

JQuery :: Syntax Error,uncaught Exception: Syntax Error, Unrecognized Expression: [@href^="mailto:"]

Jun 6, 2010

i'm a newbie on jquery i'm studying it with the latest version, and following a book called "Learning Jquery" but iencountered a error, and i don't know what the problem is:

i copied the code from the book like this:$('a[@href^="mailto:"]').addClass('mailto'); to try to change the links which start with "mailto" to the new class "mailto" but there's a error reported: uncaught exception: Syntax error, unrecognized expression: [@href^="mailto:"]

View 5 Replies View Related

Substring A Value For Display And Concatenate For Validation?

Feb 28, 2006

I have a validation script for upc codes which is currently working for
values that are entered into one text box. I've been asked to break up
the text box into 3 separate fields to accept the 1st digit, middle 10
digits, then last check digit. What I'm doing is substringing the
initial values then concatenating them. What I'm not sure of is, how to
handle the validation. I was previously firing an onBlur after the text
box but now that I have three, and I need the values to concatenate
into one for the validation. Should I just fire a function after the
3rd field that concatenates the 3 values, then pass that value to the
validation function? Or is there a better way?

I was also wondering if there was something I could find like an input
mask, but something that could just "overlay" on top of a regular text
box with one value which could give the appearance of having
separations for certain digits, in this case the first and last.

View 1 Replies View Related

Assign The Substring Of Particular Text To A Variable?

Aug 28, 2009

I would like to assign the substring of particular text to a javascript variable so that I can use the variable in an if statement.

View 3 Replies View Related

Getting A Substring From An Input Field And Then Submit It

Jul 19, 2011

I am trying to take a form input field and take what was entered and grab the first 8 character of what was entered and then submit that to a form instead of what was entered.

here is what I have. Form

<form id="form" name="myForm" action="https:websiteSubmittingto.com" method="POST">
<label>inputfield1</label><br/><input type="text" name="inputfield1" style="width:150px;"/><br/>

[Code].....

I have tried putting a onsubmit on the form tag but that got me no where.

View 4 Replies View Related

Replace Last Occurrence Of A Substring From A String

Feb 9, 2011

I am looking for a function that will replace last occurence of a substring from a string: tmpStr: xxx, yyy, zzz, sss, The desired outcome: xxx, yyy, zzz and sss (ie: remove last letter and then replace last occurrence of ",") The string can differ,

* xxx,
* xxx, yyy,
* xxx, yyy, zzz,

Do anyone of you have a neat fuction for that? I will be so happy for all input!

View 6 Replies View Related

JQuery :: Using A URL Substring To Target Tabs On Page Load?

Apr 28, 2011

I'm trying to read the substring of a url so when the page loads up, it would know if it needs toimmediatelyjump to another tab.So a user clicks a link like this:[URL] On that page, there are already functions listening for click events on objects with a class names like "gotoTab2".So all I really need is for jquery to check if there's a '#something' in the url when the page loads up, and if so execute a 'click' on that substring as if it was a class.

View 3 Replies View Related

How To Retrieve Just The Date And Use The Substring() Method On The LastModified Property?

Apr 5, 2011

I have been able to use javascript to place the last modified date in the bottom left corner of my document however I do not need the time with it. How do I use the substring() method on the lastModified property? Here is what it looks like.

<script type="text/javascript">
<!--Hide from old browsers
var today = new Date()
var dayofweek = today.toLocaleString()
dayLocate = dayofweek.indexOf(",")
weekDay = dayofweek.substring(0, dayLocate)
newDay = dayofweek.substring()
[Code]..

View 2 Replies View Related

Substring And Slice - Get The Value Of An Input Box After A Delete Key Has Been Pressed At A Certain Position

Oct 28, 2010

I'm trying to get the value of an input box after a delete key has been pressed at a certain position. For example: If I have: afghanistan and my caret is at position 4 and I push delete I will be left with: afghnistan I'm able to determine the caret position and detect the delete key and then I am trying to use slice to return the new value of the string like: Code: value.slice(caretPosition,caretPosition+1) This returns the value of what was sliced out of the string - how can I modify the parameters of slice to return everything BUT the removed part?

View 6 Replies View Related

Substring Or Trim The String - Equate The Selection Value To String "Select State" And Execute Alert Message?

Apr 19, 2010

I need help with substring or trim function in javascript. Find below my code. Selection holds the value Select State, and length of the string is 14. I need to equate the Selection value to string "Select State" and execute alert message.

function selected_item() {
if (Selection=="Select State")
alert("Select the State");[code]....

I tried this:

var state=Selection.substring(0,11); and then string would be equated to state variable. But it is not working.

View 9 Replies View Related

Syntax

Jul 20, 2005

I am trying to order a laptop from the Dell online shop but
everytime I try to press 'continue' after picking the options, I get
an error message in the lower left hand corner of the browser.
I'm using WIN 98SE with java enabled on my laptop.

The error log says:
Line: 1
Char: 1
error: object expected
code: 0

And this is the line which pops up when I place the cursor on the
'continue' button causing the above error:

javascript:next_page(&#391;','c=us&cs=19&kc=6V602&l=en&oc=5100FS&s=dhs');

I would assume there's a bug in that line. Although there's little I
can do about it other than forward it to the Dell folks - my pgming
background has me curious as to what's causing this!

View 8 Replies View Related

Is This Syntax Correct?

Jul 23, 2005

onClick="javascript:myFunction()"

or does it HAVE to be

onClick:"myFunction()"

I know 'javascript' is not necessary here, but just want to know whether to include it (which sometimes I do by mistake) is incorrect syntax or not..

View 1 Replies View Related

Syntax Error

Aug 12, 2005

I have this JavaScript that is supposed to show random products from my
database, and show something different every time you refresh or revisit.
But I keep getting an error - on my computer - that says Syntax Error in
Line 2.

There is no error on most other computers, and the products show, but
another script on the page, an article title scroller, stops - on most
computers, but not all. It says "no articles available".

I've tried the script on an asp page and a htm page, all by itself, but it
still doesn't work. I tried changing all kinds of settings in my browsers,
but nothing helps. I'm on XP, SP2, which I've heard has some problems
handling javascripts. I don't know if that's true, but if it is, I know that
lots of other people will have the same problem as me when they view the
page. Actually, I think it is a good thing, that my computer is pointing out
this error. I get the error message in IE6, but in NS8 and FF, I just don't
see the products. No error message.

Anyway, here are the first three lines of the script:

<%
if TRIM(request.servervariables("http_referer")) = "" then
%>

Using spellcheck, I found that referer is spelled wrong, it should be
referrer. I don't know if that is right for javascript (or asp?), but
correcting it didn't make a difference.

The script is JavaScript on an asp page, and it is called in an htm page.

Is the error obvious from the 3 lines?

View 8 Replies View Related

Alert Syntax

Sep 12, 2005

How does one center text in an alert box? and how do you make the alert box
appear in the middle of the screen? I've seen it done, but my alerts have
text left justified, and the box is longer than i need.

View 1 Replies View Related

Syntax -0 At End Of Replace()

Nov 13, 2006

I found this in one of my old scripts but I can't remember what the -0 was used for. I remember it was a shortcut method but I can't remember for what. Does this ring a bell with anyone?

var Pattern = /px/;
var T = paddingArry[0].replace(Pattern, "")-0;

View 5 Replies View Related

ECMAScript Syntax

Jul 20, 2005

Does the "semicolon insertion" really affect you if you format code as

function x (y)
{
// ...
}

instead of:

function x (y) {
// ...
}

The jslint page complains about lines ending in ) due to the nebulous
idea of "semicolon insertion". I have not reviewed the ECMAScript pdf
in great detail to try to pin this pretty-printing issue down. In
general, I find that code formatted in the "K&R" style (opening brace
on same line as if, while, function) confusing and difficult to read
compared with placing curly braces on separate lines.

On another subject, the difference between inner functions defined
explicitly versus defined using function expressions seems like a good
one for a FAQ. Under what circumstances does it make a real
difference whether you use function expression versus function
statement versus Function object?

View 1 Replies View Related







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