these lines :
var theSrc=document.getElementById('sb_image_'+id).src;
var srcLn=(theSrc.length)-12;
theSrc.substr(0,srcLn);
are Not working ! , the output is the same as document.getElementById('sb_image_'+id).src if i alert(theSrc);
You need to re-assign the variable to the result:
theSrc = theSrc.substr(0, srcLen);
The call to substr does not change the original string. Instead it returns a new string to you.
Related
document.getElementById("quilltext").value = '[{"insert":"12312312312312312312312312\n"}]';
var x = document.getElementById("quilltext").value;
quill.setContents(x);
doesn't work, but
quill.setContents([{"insert":"12312312312312312312312312\n"}]);
works fine.
From the question, if setContents() with array input works then you can try converting the string value with JSON.parse():
quill.setContents(JSON.parse(x));
I know the code is very little and I'm missing something small.
fiddle : http://jsfiddle.net/0oa9006e/1/
code :
var veri = "+???+Girdiğiniz eposta adresi 'adfadf' geçersiz.-???-";
var a = veri.match(/\+[\?]*\+(.*)*\-[\?]*\-/g);
a = a.replace(/[\+\-\?]*/g , "");
alert(a);
String.match(param) method returns an Array containing all matches. and array in javascript doesn't have .replace method. hence Error. You could try out something like:
a = a.toString().replace(/[\+\-\?]*/g,""); // Array to string converstion
Your match is returning an array, which doesn't have replace. Try:
a = a[0].replace(/[\+\-\?]*/g , "");
var veri = "+???+Girdiğiniz eposta adresi 'adfadf' geçersiz.-???-";
var a = veri.match(/\+[\?]*\+(.*)*\-[\?]*\-/g);
// The variable 'a' is now an array.
// The first step in debugging is to always make sure you have the values
// you think you have.
console.log(a);
// Arrays have no replace method.
// Perhaps you are trying to access a[0]?
// or did you mean to modify `veri`?
a = a.replace(/[\+\-\?]*/g , "");
alert(a);
When veri.match(/\+[\?]*\+(.*)*\-[\?]*\-/g) is executed, your variable a is initialized to a JavaScript Array, which does not have a replace method.
Use a RegEx tool like Regex101 to see how your regular expression matches on the string veri, and then perform the replace operation on the appropriate element of that array.
Here's an example of your regular expression in use: http://regex101.com/r/hG3uI1/1
As you can see, your regular expression matches the entire string held by veri, so you want to perform the replace operation on the first (and only) element returned by match:
a = a[0].replace(/[\+\-\?]*/g , "");
Hello there ,
var s = "width:20px;height:25px;color:red;font-family:myfontfamily";
i have a string like this,now how can i change the values of width,height etc using javascript.there may be a \n after or before the properties (width,height etc)..
Ex : i want to change width to 50px on s.
so it will be
var s = "width:50px;height:25px;color:red;font-family:myfontfamily";
My another replated Question is here Regular Expression to get text from css but it not working exactly what i need.
Please help me.
Thank you.
Update : You can see the Result on my fiddle here : http://jsfiddle.net/jitheshkt/s2DJR/14/
Regular expressions.
For example:
s = s.replace(/color:\s*([^;]+)/, "color:" + newvalue)
var s = "width:20px;\nheight:25px;\ncolor:red;\nfont-family:myfontfamily";
alert( s.replace(/width:\d+/,'width:123').replace(/height:\d+/,'height:456') );
I'd like to create a simple javascript concatenator that takes 2 HTML textarea tags as input, and concatenates each line from textarea 1 with each line from textarea 2.
So I think I'm basically looking for a javascript function that will generate an array from the textarea, where each new line delimits a new element in the array, like so:
Textbox:
item 1\n
item 2\n
item 3
becomes...
["item 1","item 2","item 3"]
How do I do that? I could do this pretty easily in php, but js mystifies me. If anyone can share the code that would do this, I'd really appreciate it!
Thanks,
Chris
var ary = (
document.getElementById('yourTextArea1').value +
document.getElementById('yourTextArea2').value
).split('\n');
throw an extra + '\n' between those if desired
This should work:
var str = "1\n2\n3 4";
var strArray = str.split("\n");
myArray =(document.getElementById('a').value+document.getElementById('b').value).split('\n');
You can use what #cwolves provided, but it might not work on PCs that use a carriage return instead of a line feed. Here's a script that fixes that and also can join all textareas:
var ta=document.getElementsByTagName("textarea");
var vals=[];
for(var i=0;i<ta.length;i++){
vals.push(ta.value.replace(/\r\n|\n\r/gim,"\n").replace(/\r/gim,"\n");
}
var val=vals.join("\n")
var ary=val.split("\n");
So here the textareas on the page are put into the "ta" variable, then we replace carriage returns with line feeds. The result of it being split into an array is in the "ary" variable.
Ad#m
Just wandering will it be possible to partially string replace in jquery?
I have try to using the following code, but this is not seem working for me:
var test = "testing_supplyAddress_001";
test.replace('supplyAddress', 'billingAddress');
I tried to replace only supplyAddress to billingAddress so the output will be testing_billingAddress _001
JavaScript strings are static and thus .replace() does not actually modify the string. You'll need to assign the value returned by the .replace() function back to the variable:
var test = "testing_supplyAddress_001";
test = test.replace('supplyAddress', 'billingAddress');
Here's a demo showing this in action ->
It works fine. It doesn't replace it in place though - the replace() method returns a new string.
var test = "testing_supplyAddress_001";
var newTest = test.replace('supplyAddress', 'billingAddress');
alert(newTest);
This is just plain old javascript - but will work with jQuery too.
var test = "testing_supplyAddress_001".replace('supplyAddress', 'billingAddress');