how to receive GET parameter from current page with js [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I need to receive get parameter from the current page to do xhr request further. I've tried to set data- tags but I think this kludge is not a good deсition.

Give this a try
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}

Related

How do I use concatenated string in a DIV? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I think my concatenating is fine, but my use of it isn't working. Any help would be appreciated. Thanks.
<script>
var str1 = "/images/";
var str2 = "test.jpg";
var res = str1.concat(str2);
</script>
<div class="product-sprite" data-image="res"></div>
DOM element attributes are not evaluated as variables. You need to assign it to the element property.
var res = str1 + str2; // no need to use .concat()
document.querySelector(".product-sprite").dataset.image = res;

Javascript cant append elements [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am getting some data from my server and I want to create element but this code is not working please help me
var filelist=['dummy1','dummy2','etc']
filelist.forEach(file=>{
var newli=document.createElement("li")
var newa=document.createElement("a")
newa.innerHTML=file
newa.setAttribute('href',file)
newli.append(newa)
box.append(newli)
})
Note the box is a div in above code
Here you go, this is working. One needs to assure that before the execution of any DOM accessing functionality, the former has to be ready/loaded.
const fileNameList = ['dummy1', 'dummy2', 'etc'];
const box = document.getElementById('box');
fileNameList.forEach(fileName => {
const newLi = document.createElement("li");
const newA = document.createElement("a");
newA.innerHTML = fileName;
newA.setAttribute('href', fileName);
newLi.append(newA);
box.appendChild(newLi);
});
<div id='box'>Your box</div>

write c# code in JavaScript function in Razor [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
my question is very short want to this :
$(document).on('click', '.ee', function(){
$('.b').val("#Model.Result.GoingDate.AddDays(-1).ToString()");
#{Model.Result.GoingDate = Model.Result.GoingDate.AddDays(-1); }
});
but it's not working
is there any other way to that?
I know I can use javascript date
but don't know how
you cant do that with razor instead
use this method I kind of know what you need
you want to go to next day and update your text in HTML
$(document).on('click', '.ee', function () {
var currentDate = $('.txt-date').val();
var gdate = new Date(currentDate);
gdate.setDate(gdate.getDate() + 1);
$('.b').val(goingDate.toISOString().substring(0, 10));
});

function that returns first object of a given array [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
function first(array){
return first(0);
var first = ["gold","brown","green"21,1998];
console.log(first[0]);
trying to create a function that will return the first object of a given array, and am getting an error self[e.data.invoke.func].apply is not a function
not sure what I'm missing?
I tried this and it worked
function firstObject(array){
return array[0];
}
var first = ["Weresquirrel", "Werebear", "Werepanda", "Weremonkey"];
console.log(firstObject(first));

How to add var in get value in JavaScript? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
How to add var in get value in JavaScript ?
I have 2 var
var page = $('#demoajax').val();
var name = $("#users").val();
This is mym old code
data:"server=Windows&actionfunction=showData&page="+page,
I want to add var name and value now=date to this line how can I do that ?
First I try this
data:"username="+name+"&server=Windows&actionfunction=showData&page="+page+"&now=date",
But not work.
You appear to have inserted your changes in the middle of the query string. Try this instead.
data:"server=Windows&username="+name+"&actionfunction=showData&page="+page+"&now=date",
Why do you have data:"username="+name+"&server=Windows&actionfunction=showData&page="+page+"&date=now",
switch date and now
Also lose the comma at end if not needed

Categories