C# in Javascript Element on CSHTML page [duplicate] - javascript

This question already has answers here:
Mixing razor and java script code for #Html.Partial()
(2 answers)
Closed 6 years ago.
How can I use c# code in a Javascript statement?
This is my code:
document.getElementById('part1').innerHTML = '' +
'#Html.Partial("SelectCustomer.Views")'
' Views';
#Html.Partial("SelectCustomer.Views") and <%= and %> do not work

#Html.Raw("document.getElementById('part1').innerHTML = '' +
#Html.Partial("SelectCustomer.Views")
' Views';");
Don't have razor project on hand to test it. Might need to remove the # from the second Html.

Related

How to include a PHP variable in Javascript code? [duplicate]

This question already has answers here:
How do I pass variables and data from PHP to JavaScript?
(19 answers)
Closed 5 years ago.
[1] http://imgur.com/a/Ny8f7 "html code"
[2] http://imgur.com/a/kzEN2 "php code"
I try to use the variables from php in javascript to generate a chart with them.
Try using an id e.g.
In your html
name='someName'>
Then use that ID in your JS.
Use can use something like this:
var data = '<?=$dataFromPhp?>';

JS code into PHP code [duplicate]

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
I can not add JS code into PHP code
JavaScript File:
$.each(data.data,function(i,modul){
tb.append("<p><?php if (!is_dir($rootPath . '/Includes/'" + value.id+ "'")) { ?> <span>Test</span><?php } else { ?> <span>Test</span><?php } ?></p>"});
This line:
' + value.id+ ' = This is a JS code
Where do I make mistakes?
Thanks

Javascript equivalent of PHP's "print" [duplicate]

This question already has answers here:
Is there a php echo/print equivalent in javascript
(9 answers)
Closed 8 years ago.
If I have some PHP HTML that reads like this:
<html> I am feeling <?php print urldecode($_GET["emotion"]);?> today!</html>
and Get's "emotion" in URL title is "Happy", the HTML renders "I am feeling Happy today!".
Now, migrating away from PHP, how do I do this with javascript?
In Javascript I have a variable $emotion = "Happy"; so what Javascript goes inbetween the script tags below (where there are currently asterisks********)
<html> I am feeling <script>*********************</script> today!</html>
You can do it easily by putting an element where you want the text to change, then accessing that element by it's id.
$emotion = "Happy";
var e = document.getElementById('emotion');
e.innerHTML = $emotion;
I am feeling <span id="emotion"></span> today!

PHP $_Get and JQuery .load [duplicate]

This question already has answers here:
Encode URL in JavaScript
(22 answers)
Closed 8 years ago.
I want to load another page via Javascript like this
$("#resultarea").load("searchresults.php?searchstring=" + $("#searchbox").val());
in searchresults.php, a single statement
echo $_GET["searchstring"];
what I type in searchbox appears when searchresults.php is loaded except when I add space and another word, no thing appear at all. I heared it can be done by encoding or somewhat, I searched but didn't find a solution.
Try encodeURIComponent:
var encodedValue = encodeURIComponent($("#searchbox").val());
$("#resultarea").load("searchresults.php?searchstring=" + encodedValue);
Source
Demo

How to strip out all html tags from string [duplicate]

This question already has answers here:
Strip HTML from Text JavaScript
(44 answers)
Closed 8 years ago.
Here is the code I have:
I want to make sure the user doesn't put any html tags in the "Add Responsibilities" field. So for example, if the user writes this:
<div>Test</div>
Then it would put this into the responsibility field:
Test
I think it's something to do with this command but I can't get it working within my code:
$("#resp_input").html( $("#resp_input").text() );
You may use this code:
$('#responsibilities').text($("<div>" + eachline + "</div>").text() );
see this update

Categories

Resources