function SimpleSymbols(str) {
var letter =['a','b','c','d','e','f','g','h','i','j',
'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
var newstr = "";
for (var i = 0; i<str.length; i++){
if (str.charAt(i).toLowerCase() in letter){
newstr += "M";
}
else{
newstr += "X";
}
}
return newstr;
}
If str is "Argument goes here" it returns XXXXXXXXX. WHy doesn't it return MMMMMMMMMM?
Given the following string:
var str = "one,two,three";
If I split the string on the commas, I normally get an array, as expected:
var arr = str.split(/\s*,\s*/);
Trouble is that in Google Chrome (for Mac), it appends extra properties to the array.
Output from Chrome's debugger:
arr: Array
0: one
1: two
2: three
constructor: function Array()
index: undefined
input: undefined
length: 3
So if I iterate over the array with a for/in loop, it iterates over the new properties. Specifically the input and index properties. Using hasOwnProperty doesn't seem to help.
A fix would be to do a for loop based on the length of the Array. Still I'm wondering if anyone has insight into why Chrome behaves this way. Firefox and Safari don't have this issue.
I have a version number with 3 digits as a String,
var version = "1.2.3";
and would like to compare it to another version. To see if version is newer than otherversion,
var otherVersion = "1.2.4";
How would you do it?
Is it possible to read/edit iframe contents(not only properties like src) with scripts that are on page but outside of this frame? I know that is impossible if source is from other site as it would be a big serurity hole, but I only ask whether it works for other content from the same origin.
i have a textbox in asp.net form.... if i entered numbers not like 7 or 8 or 9, then script function should be araised with alert message.... how to achieve this.... that 7 or 8 or 9 are first digits in my texbox...
Hi,
I have a problem with JQuery Context Menu ( link text ) and iframe.
If i use it inside, the context menu is naturaly shown inside. But it will be partialy shown.
I am searching how to resolve it.
Please note that the context menu only appear when i click on specific iframe's elements.
thanks :)
function main(){
var delImage=document.createElement("img");
delImage.setAttribute("alt","Edit");
delImage.setAttribute("src","drop.png");
var position=newRow.rowIndex;
var typeElem=document.createElement("a");
typeElem.setAttribute("name","delete");
typeElem.setAttribute("href","#");
typeElem.appendChild(delImage);
typeElem.setAttribute('onclick',"delete(position)");
newRow.insertCell(lastCell).appendChild(typeElem);
}
function delete(pos){
alert(pos);
}
i am not able to call the delete function when anchor tag was clicked...what can i want to change to achieve this?
I create windows like this:
var obj = document.createElement('div');
obj.className = 'window';
obj.style.width = 300 + 'px';
obj.style.height = 200 + 'px';
obj.style.left = 30 + 'px';
obj.style.top = 200 + 'px';
//and so on
and what I need is to attach some data to each window. The data will be grabbed via Ajax and displayed in the windows. How should I do it so that each window hold its own unique data?
I don't need to display the whole data every time and this data would need be organized before being displayed, so I can't just add it with innerHTML. I need a way to hold it somewhere else where I could easily get it and then display it with innerHTML.
Hi..I recently bumped into this link
http://mootools.net/slickspeed/
I was amazed to see that the prototype is extremely slow. So I would like to know your comments on this?
Hi - I have this script on my html page:
parent.resizeTo(550,510);
I'd like to add to it so it positions the window in the middle of the screen. Also, I want to remove the address and tool bars (I've managed to hide the scrollbars by using body{overflow:hidden;}).
I know how to do this using JS upon opening a new window from the browser but this needs to work from clicking a link on a PDF.
Does anyone have any suggestions? Thank you!
I'm grabbing the query string parameters and trying to do this:
var hello = unescape(helloQueryString);
and it returns:
this+is+the+string
instead of:
this is the string
Works great if %20's were in there, but it's +'s. Any way to decode these properly so they + signs move to be spaces?
Thanks.
Hi,
I wanted to know how I could find the previous active control on a page. I have a couple of textboxes and a button, and when i am on a certain textbox and I click the button, I want to highlight that textbox. I have the highlight functionality covered, but I don't know how to find out which textbox to run the function on...
Please help,
Thanks!
I'm rubbish at Regular Expressions, really!
What I'd like is to split a string containing a CCS property value into an array of [string,value,unit].
For example: if I supplied the .split() method with 1px it'd return ["1px",1,"px"]. If I were to supply, similarly, 10% it'd return ["10%",10,"%"].
Can this be done?
I appreciate all your help!
I have the following BaseClass defined:
function BaseClass (arg1,arg2,arg3) {
//constructor code here then -
var privateVar = 7500;
this.getPrivateVar = function() { return privateVar; };
}
I want to have the following subclass which allows changing privateVar like so:
function SubClass (arg1,arg2,arg3,privateVar) {
//constructor code here then -
var privateVar = privateVar;
}
SubClass.prototype = new BaseClass();
Now I want SubClass to inherit the getPrivateVar method. However, when I try this, it always returns 7500 which is the value in the BaseClass and not the value of privateVar.
In other words, is it possible to inherit a BaseClass's public methods but have any references in them refer to the SubClass's properties? And how would I do that?
Hey guys,
I want to create a form which has a text entry box where a user can enter their name and then I want a button as well. But what I want this button to have a function called ReadName() where what will happen is when the user clicks on the button it will come up with a message saying "Hello user name will appear here
I have tried my self and but I don't think I am not getting what I want. Any help will be appreciated.
<form>
<label for="name">Name:/label>
<input type="text" name="name" id="name"/>
<input type="text" name="name" onfocus="ReadName()"/>
</form>
I have something like this:
var test = {};
function blah() {
test[2] = 'filled';
}
console.log(test);
//result test -> 2:"filled"
console.log(test[2]);
//result undefined
I don't understand why I'm getting 'undefined' in the second instance when according to the first instance, the property of that object clearly exists!
Does anyone have any ideas?
Thanks
Hi All,
Is there a way in any browser to add/remove class names? For example, if I have a div with class names and I just want to remove/add 'name2' is there a way to do that?
Thanks,
rodchar
Greetings,
The question relates to ASP.NET MVC
I am creating some divs dynamically using AJAX (some views render dynamically). Inside these views a have some JS code. When user click on link i would like to open dialog box with google map. However, because these views are rendered dynamically it does not work because js code is not injected (what can be seen in page source). How can I resolve this problem?
I'm using custom tags to define sections in an application, so I have something like this:
<mysection>
<form>
<input name="myfield">
</form>
</mysection>
I'm using the following and able to get the tag (printed to console, everything is groovy)
var parent = document.getElementsByTagName('mysection');
The issue I'm having is finding the child field by name:
var myfield = parent.getElementsByName("myfield");
...as I don't want to pick up on any other 'sections' that might have an input with the name 'myfield'.
EDIT:
var parent = document.getElementsByTagName('mysection')[0];
was suggested and returns to console the section contents, however, getElementsByName throws an error:
Uncaught TypeError: Object #<NodeList> has no method 'getElementsByName'
I am trying to make method chaining work in conjunction with my constructors, but I am not exactly sure how to go about it. Here is my code thus far:
function Points(one, two, three) {
this.one = one;
this.two = two;
this.three = three;
}
Points.prototype = {
add: function() {
return this.result = this.one + this.two + this.three;
},
multiply: function() {
return this.result * 30;
}
}
var some = new Points(1, 1, 1);
console.log(some.add().multiply());
I am trying to call the multiply method on the return value of the add method. I know there is something obvious that I am not doing, but I am just not sure what it is.
Any thoughts?
Hi
I want to make an if statement that if the value is not defined then let it go through.
I tried
if (something != "undefined")
and
if (something !== "undefined")
However it seems to go into the if statement no matter what. If it is undefined it goes through. If it is defined it goes through. Am I doing something wrong?