converting c# objectid to string in javascript [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
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.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
i have a objectId on my mvc model which i want to sent to a mvc API call, which results in a
"Uncaught SyntaxError: Invalid or unexpected token"
<script>
$(function () {
$('.btn-saveshedule').click(function () {
var selectedValue = $("#sel1 option:selected").val();
var userid =#Model.Id.ToString();
var json = getTimeSlotsInJson($('.schedule'), userid.str, selectedValue);
});
});
</script>
how on earth do i convert #Model.Id to a string?

You just need to put single quotes around it:
var userid ='#Model.Id.ToString()';

Related

Set parameter as element id then change its value in loop [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have a code here:
$.each(localStorage, function(key, value){
if (key.indexOf('(cache)') > -1) {
var id = key.replace("(cache)", "");
id = '#' + id;
$(id).val(value);
}
});
My target is to update the value of the specific id but it gives an error of unkown expression (expected id here)
and also here is the image of the error
It's highly recommended to convert id properly (don't use dates and spaces). But if you can't then below is a solution
Working snippet:-
myval = 1;
id= '05/03/2018 15:39:51JxM8tX8K';
$('[id="'+id+'"]').val(myval);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="05/03/2018 15:39:51JxM8tX8K"><br>
<input type="text" id="05/03/2018 15:39:51JxM8tX8KDKHFCK">
Note:-I am not fully sure that it will work for you perfectly or not. Test it and let me know

Adding a onclick event to a span - [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
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.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I am struck with adding a onclick function to my span - though it looks simple - I am sure - there is something I am missing
Please find the code sample below
https://jsbin.com/naqejanigu/edit?html,css,js,output
function conv() {
var cel = document.getElementbyId('unit');
cel.innerHTML = 'F';
}
function conv() {
var cel = document.getElementById('unit');
cel.innerHTML = 'F';
}
getElementbyId should be getElementById.

JavaScript match() function does not give output [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
In JavaScript code I use regular expression match() function to find pattern and show the result, but it does not give a proper answer, means finding [i] character in giving sentences
<button onclick = "searchPattern()">pattern</button><br>
<p id = "demo"></p>
<script>
function searchPattern(){
var str = "Visti W3Schools!";
var paat = /[i]/g;
var result = str.match(patt);
document.getElementById("demo").innerHTML = result;
}
</script>
Read your JavaScript console
Uncaught ReferenceError: patt is not defined
You changed your variable name from paat to patt half way through your code.

How to remove value from array? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
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.
Improve this question
I wanted to insert value in if condition and remove it in else condition.
$(document).ready(function(){
var ids=[];
$('input[type="checkbox"]').click(function(){
if($(this).prop('checked')){
var id = $(this).val();
ids.push(id)
}
else
{
//remove value from array
}
});
});
Instead of :
array.push(id)
It should be :
ids.push(id)
(because your array name is ids not array)
Click event's callback function parameter is event
$('input[type="checkbox"]').click(function(array){
"array" is instance of event on above code.
Then variable "array" cannot have function "push".

Why am I unable to convert this json into a string? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have json data I'm having difficulty turning into a string. How can I format it so that it can become strings?
jsfiddle: http://jsfiddle.net/s97QX/2/
code:
Jsonvar = {"shows":[{"show_id":6387, "shownum":6387,"title":"The Protestant's Dilemma","guest":"Devin Rose","category":"Non-Catholic","url":"http://www.catholic.com/radio/shows/the-protestants-dilemma-11565","audiourl":"http://www.catholic.com/sites /default/files/audio/radioshows/ca140331b.mp3","datetime":"1396317600","description":"
Devin Rose <\/p>","thumbnailsmall":"http://www.catholic.com/sites/default/files/imagecache/profile_square_small/images/profilepics/a109aad8daa70ad8976ffc.L._V387899120_SX200_.jpg","thumbnaillarge":"http://www.catholic.com/sites/default/files/imagecache/profile_square_large/images/profilepics /a109aad8daa70ad8976ffc.L._V387899120_SX200_.jpg"}]};
var jsonstr=JSON.stringify(Jsonvar);
alert(jsonstr);
First You validate your json using jsonlint.
JSONLINT
then try.
This error in the console explains it:
Uncaught SyntaxError: Unexpected token ILLEGAL
You have a line break in your object:
Jsonvar = {"shows":[{"show_id":6387, "shownum":6387,"title":"The Protestant's Dilemma","guest":"Devin Rose","category":"Non-
Catholic","url":"http://www.catholic.com/radio/shows/the-protestants-dilemma-
11565","audiourl":"http://www.catholic.com/sites/default/files/audio/radioshows/ca140331b.mp3"
,"datetime":"1396317600","description":" <<<- Here
Devin Rose
Remove that and that property will become a valid string, therefore you'll be able to stringify it

Categories