Get Textarea Value with Simpe HTML Dom - textarea

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>

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).

Textarea New Line on Enter Key not working on .NET Core MVC Application

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.

Styling single jQuery UI controlgroup-item

I am using jQuery UI controlgroup to style checkboxes in an HTML form. After the input values are processed by a PHP script, the results are displayed on the the same page along with the form itself, so that the user can adjust the filters. What I am trying to do, is to have the boxes that were checked previously remain checked after the form has been processed, so that the user sees what selection criteria were used. To achieve that I store all the PHP $_POST data in a JS variable using json_encode, which I'd like to use to iterate through the labels and mark those that were checked previously. The problem is that the only option of the controlgroup widget that I can use is classes with ui-controlgroup-item which shows every single label within the group as active, and for the life of me I cannot figure out how to make it conditional, e.g. so that I can use if(label[for=' + var.value +'])', var being <?php echo json_encode($_POST) ?> or something similar. Will appreciate any suggestions.
Here is the HTML:
<div id="currencyList">
<label for="gbp">GBP</label>
<input type="checkbox" value="gbp" name="currency[]" id="gbp" >
<label for="usd">USD</label>
<input type="checkbox" value="usd" name="currency[]" id="usd">
<label for="eur">EUR</label>
<input type="checkbox" value="eur" name="currency[]" id="eur">
</div>
And this is the JavaScript bit:
$( "#currencyList" ).controlgroup({
classes: {
"ui-controlgroup-item": "ui-checkboxradio-checked ui-state-active"
}
});
After trying to find a solution for several days I decided to skip trying via the classes option and instead to move outside the controlgroup widget. So here is my not-so-pretty-but-working solution:
var postData = <?php echo json_encode($_POST) ?>;
$( "#currencyList" ).controlgroup();
$('#currencyList').children('label').each(function () {
if(postData.currency.indexOf($(this).attr("for")) >= 0){
$(this).addClass( "ui-checkboxradio-checked ui-state-active");
}
});

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") + "')")" />

POST value of date picked in YUI calendar

I've been looking every where, and the tutorial doesn't seem to work when I use it. I saw something like getfullmonth, getfullyears etc. ... anyway, I'm using this code:
My js:
<script>
YAHOO.namespace("example.calendar");
YAHOO.example.calendar.init = function() {
YAHOO.example.calendar.cal1 = new YAHOO.widget.CalendarGroup("cal1","cal1Container", {PAGES:1});
YAHOO.example.calendar.cal1.render();
}
YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);
</script>
And this is my HTML:
<input type="text" value="I WANT TO PUT THE SELECTED DATE HERE" id="datechoix" class="n-input2" name="datechoix" readonly="readonly" />
<div id="cal1Container" style="margin-top:15px;"></div>
Anyone got a good tutorial or a complete answer maybe?
You have to listen to the select-date-event. It fires if a user selects a date and holds the date information as arguments.
See this example:
http://yui.github.io/yui2/docs/yui_2.9.0_full/examples/button/btn_example09.html

Resources