Textarea New Line on Enter Key not working on .NET Core MVC Application - asp.net-mvc

I have a (probably) simple issue that I can't solve and need your help to resolve.
I created a new MVC application with Visual Studio 2017. I then created the necessary Model, View, and Controller to add some data to a SQL Server database.
However, in the TEXTAREA input, I am not able to use the Enter Key to go to a new line, like I am able to do here when I submitted this question. The Enter key does nothing.
I tried to trace the issue and was able to use this script to confirm that the Enter key was detected; however, still can't get a new line when I pressed the Enter key.
<script>
$(window).keydown(function (event) {
if ((event.which == 13) && ($(event.target)[0] == $("textarea")[0])) {
alert("One");
// event.preventDefault();
// return false;
}
});
</script>
Second, I added an onclick event to the textarea itself and still did not get a new line when clicked. There must be an override for the textarea in code that I am not able to find, which is probably part of the default app build in .NET VS2017.
<textarea rows="6" cols="20" class="form-control" asp-for="Notes" style="width: 96% !important;" onclick="this.value='Hello \n How R U?'"></textarea>
Is there any way to correct this issue and gain access to the full TEXTAREA functionalities and be able to provide a full text-based area for users to provide detailed comments in multiple lines?
Thank you for your reply.

I wrote following HTML code to face your problem but there was no problem!
<html>
<head>
<title>
test
</title>
</head>
<body>
<textarea rows="6" cols="20" class="form-control" asp-for="Notes" style="width: 96% !important;"
onclick="this.value='Hello \n How R U?'"></textarea>
</body>
</html>
Did you check your application by another browser?
If the problem still remains, In your browser inspect HTML code of your textarea and compare it to the tag helper equivalent of the textarea in your view code. This may help you to figure something out.

Related

Order of HTML element bindings in Svelte

New to Svelte here and playing with the reactivity concept. This first example works, the file input field correctly shows the selected file.
<script>
let files = []
</script>
<input type='file' bind:files />
This second example (only swapped the input attributes) does not. As can be easily tested in the REPL.
<script>
let files = []
</script>
<input bind:files type='file' />
It complains with "Value being assigned to HTMLInputElement.files does not implement interface FileList." and I don't understand why... do the bindings always have to go last in Svelte?
As #RichHarris explains above... this is a bug in Svelte. For now simply add the bindings to the end of the input element until it has been fixed.
See the Github issue for more info.
UPDATE: This has been fixed in November 2019 (see pull request #3849).

Microsoft edge v 17.17134 displays a # on postback

I recently stumbled upon a weird problem with the last version of Microsoft Edge (17.17134).
I have a really simple classic asp form that posts data to another asp form. If I post a string which contains
input
and
onclick=""
the receiving page will only display a "#" even if the code behind seems ok(see screenshot)
here's a snippet:
<!doctype html>
<html>
<body>
<form method="POST" action="to.asp">
<input type="text" name="hidInnerHTML" id="hidInnerHTML" style="width:500px;" value="steve would like your input on what to do when you activate the onclick= method" />
<br />
<input type="submit" value="click me"/>
</form>
</body>
</html>
and here is the code at the receiving end:
<!doctype html>
<html>
<body>
<div style="border:1px solid red;"></div>
</body>
</html>
It seems that certain keyword in the post data will trigger this effect. IE, chrome, probably Firefox, previous version of edge - all work correctly.
Any clues or idea what is happening here?
I'll take all the help I can get! :)
After doing a bit more research, i can see that this exact issue has just been raised here...
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/19045578/
Check out the link for a fuller explanation but the short story is that you either set a "X-XSS-Protection" response header on your site with a value of "0" or you wait for the Windows 10 Insider Preview version (Build 17758) of Edge which includes the fix for this bug.
Microsoft Edge 44.17758.1.0
Microsoft EdgeHTML 18.17758

Get Textarea Value with Simpe HTML Dom

i using simple_html_dom.php
how to get textarea value if the website has used bad tag.
the textarea tag already closed before </textarea> like input tag.
Textarea HTML like below:
<textarea name="xxx" id="xxx" />this is value</textarea>
When i use this function, i dont get anything
$textarea = $html->find("textarea[name=xxx]");
$contents = $textarea->innertext;
echo $contents;
how to get 'this is value' using simple_html_dom.php or other alternative?
Thank you
Well, my previous comment won't work in this case, I'll leave it for info though...
Another approach is to clean it up before parsing it with simple_html_dom using Tidy extension. But it seems not to be working here either...
A last approach I can think of, and if this is your only problematic case, is to use regex to get what you want:
Using <textarea.*?name="xxx".*?id="xxx".*?\/>([^<]+)<\/textarea> ==> RegEx DEMO
The output will be in group one of the resulting array $match. Check this working code:
$input = <<<_DATA_
<textarea name="xxx" id="xxx" />this is value</textarea>
_DATA_;
$pattern = '/<textarea.*?name="xxx".*?id="xxx".*?\/>([^<]+)<\/textarea>/';
preg_match($pattern, $input, $match);
var_dump($match)
Working DEMO
It is easy to get the value of a Teaxtarea in javascript:
<script type=text/javascript>
function getValueTextarea()
{
var vl=document.getElementById("tx").value;
alert(vl);
}
</script>
<body>
<textarea id="tx">Value Of Textarea</textarea>
<input id="button" value="Get Value" onclick="getValueTextarea()">
</body>

Can't get onclick on a button to be accepted

I currently have a link in the below form:
Change
In order to fit the look of the site in which I'm adding this link, I want to change it to a button input, as so:
<input type="button" value="Change" onclick="changeNumbers('Numbers', '#Url.Action("ChangeNumbers")')" />
However, I'm running into a snag with this second form: the single quotes around #Url.Action("ChangeNumbers") are being flagged as Unterminated string constant. Can anyone tell me what I'm doing incorrectly and how to fix it?
EDIT
It didn't occur to me to just try the page - it looks like the second form works. So now my question is - why is Visual Studio flagging this as incorrect?
You're not doing anything "incorrectly" per se, it's just that Razor isn't perfect, and things like quotes within quotes tend to cause it to freak.
One quick fix would be to store the URL in a variable and then use the variable:
#{ var url = Url.Action("ChangeNumbers"); }
<input type="button" value="Change" onclick="changeNumbers('Numbers', '#url')" />
However, an even better fix is to not use the onclick attribute at all. Put this where it belongs: in JS.
<script>
$('#myButton').on('click', function () {
changeNumbers('Numbers', '#Url.Action("ChangeNumbers")');
});
</script>
Used jQuery above, since it's included in MVC by default
I've found that to make Visual Studio happy in this scenario, the easiest thing to do is simply change the <input /> element to a <button></button> element and the error will resolve itself:
<button type="button" onclick="changeNumbers('Numbers', '#Url.Action("ChangeNumbers")')">Change</button>
Otherwise, to continue using an <input /> the markup will need to be changed to the following:
<input type="button" value="Change" onclick="#("changeNumbers('Numbers', '" + Url.Action("ChangeNumbers") + "')")" />

Dart: How to close browser window?

How can I close a browser page via eg. an HTML button and Dart?
I've tried
window.close();
which doesn't appear to do anything;
I've also tried :
window.document.$dom_dispatchEvent();
using CloseEvent, but I'm not sure how to set that up.
I've also tried HTML and javascript without success.
Please advise how this can be done. It's needed for desktop-type apps IMO.
I used this:
<form method="post">
<input type="button" value="Close Window"
onclick="window.close()">
</form>
Maybe try
window.focus(); window.close()

Resources