Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have an event:
javascript: AbrePesquisa ('/page/Test.asp?parm1=False');
The AbrePesquisa
function:
AbrePesquisa function (url)
{
url = url.replace = ("?" , "$$$");
...
}
In the IE, the url is coming with "$$$" ('/page/Test.asp$$$parm1=False') but it comes in chrome with "$$" ('/page/Test.asp$$parm1=False').
Why is this happening?
If you look at the docs for String.prototype.replace you'll see that $ is a special character used to include parts of the matched string in the replacement. To get what you want, you'll have to do url.replace("?", "$$$$$$");
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm trying to make a subpattern and to show it on the screen by using res.send, like so:
app.get('/r/:something', (req, res) => {
const { something } = req.params;
res.send('<h1>Browsing the ${something} on the screen</h1>')
})
You need to use backticks for templated strings not single quotes
res.send(`<h1>Browsing the ${something} on the screen</h1>`)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
The community is reviewing whether to reopen this question as of 2 years ago.
Improve this question
So if i have some codes like this
If(sceneA){document.getElementById("divA").src="A.png";}
If(document.getElementById("divC")=="A.png"){document.getElementById("divB").src="B.png";}//And alot of codes here
How can I use a var to shorten strings like
document.getElementById("divA").src="A.png"
document.getElementById("divB").src="B.png"
so i can use them both inside (IF) and {function}
As they have to repeat quite a few times in the codes.
Thanks alot!
That's exactly what functions are for.
Define a function for repeating blocks of code as follows:
function setSrc(divName, imgName){
document.getElementById("div"+divName).src = imgName+".png";
}
function srcEquals(divName, imgName){
return (document.getElementById("div"+divName).src == imgName+".png");
}
Then you can replace your code with this:
if(sceneA){setSrc("A","A");}
if(srcEquals("C", "A")){setSrc("B","B");}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to remove First and Last Quotes from this array Using JavaScript:
"["Morning Shift","Day Shift"]"
After Remove quotes output look like this
["Morning Shift","Day Shift"]
You can try using JSON.parse():
The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string.
Demo:
var data = `["Morning Shift","Day Shift"]`;
data = JSON.parse(data);
console.log(data);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Hello i have an object in JavaScript which contains this:
{Coc Coc={30daysAgo=1}, Mozilla={30daysAgo=1}, BlackBerry={30daysAgo=1}, Safari={30daysAgo=140}, Firefox={30daysAgo=192}, YaBrowser={30daysAgo=6}, Internet Explorer={30daysAgo=72}, Safari (in-app)={30daysAgo=40}, Android Browser={30daysAgo=3}, Chrome={30daysAgo=1387}, SeaMonkey={30daysAgo=1}, Edge={30daysAgo=7}, Opera={30daysAgo=7}}
How can i insert in a variable only the names of the browsers without the rest?
e.g var browsers = Mozilla,BlackBerry,Safari etc...
Try this:
var a = {"Coc Coc":{"30daysAgo":1}, Mozilla:{"30daysAgo":1}, BlackBerry:{"30daysAgo":1}, Safari:{"30daysAgo":140}, Firefox:{"30daysAgo":192}, YaBrowser:{"30daysAgo":6}, "Internet Explorer":{"30daysAgo":72}, "Safari (in-app)":{"30daysAgo":40}, "Android Browser":{"30daysAgo":3}, Chrome:{"30daysAgo":1387}, SeaMonkey:{"30daysAgo":1}, Edge:{"30daysAgo":7}, Opera:{"30daysAgo":7}};
var browsers = Object.keys(a).join(",");
Result:
Coc Coc,Mozilla,BlackBerry,Safari,Firefox,YaBrowser,Internet Explorer,Safari (in-app),Android Browser,Chrome,SeaMonkey,Edge,Opera
Fiddle
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a special ID in the format of A000000004..A000000150 etc and OD000000001..OD000000150. I have read the forums here and tried out the solutions (many in the form of /^([A]{1}\[0-9]{9})$/ etc.) but none of them have helped.
I hope I'm understanding your question properly, but how about this regex?
/^(A|OD)[0-9]{9}$/
To check a string against this regex, you'd use something like this:
var regex = /^(A|OD)[0-9]{9}$/;
if (regex.test(myCode)) {
// ... do something ...
}
***So the final solution to my question for people who will refer in future:
The code will be:
var regex= /^(A|OD)[0-9]{9}$/;
var myCode=document.forms["formname"]["fieldname"].value;
if(!regex.test(myCode))
{
alert(...);
return false;
}