How to convert Html text into normal plain text? - actionscript-3

I have html text which is coming from backend and i need to convert it into normal text to show up in TextArea.
Is there any way to convert Html text into normal plaintext by usingFlex framework`?

You will have to use Regexp to remove tags.
From here:
var myString:String = "<p><b>bold</b> <i>italic</i> <a href='#'>link</a> <br>linebreak</p>";
trace(myString)
var removeHtmlRegExp:RegExp = new RegExp("<[^<]+?>", "gi");
myString = myString.replace(removeHtmlRegExp, "");
trace(myString);
// OUTPUT
// <p><b>bold</b> <i>italic</i> <a href='#'>link</a> <br>linebreak</p>
// bold italic link linebreak
In case I got you wrong and you want to display HTML tags in textarea, use escape() function

Related

Using jquery to have one html element point to another

I am new to jquery and was wondering how I can point one html element equal to another. I want to make it so that whenever something in the h2 tag changes, the text within the p tags will copy the change. Below is how my tags are set up within the class fc-center.
var title = $('div.fc-center h2').text();
$('.fc-center').append('<p>'+'' +'</p>');
with the html looking something like
<div class = 'fc-center'>
<h2> text text</h2>
<p> </p>
</div>
essentially what I want to do is something like this :
$('div.fc-center p').equalto $('div.fc-center h2')
But I am not quite sure how to go about it
I propose this solution:
var title = $('.fc-center').find('h2').text();
var elementsP=$('.fc-center').find('p');
if (elementsP.length > 0) {
$.each(elementsP, function(i, val) {
$(this).empty().html(title);
});
}
https://jsfiddle.net/julian9319/grc0y6qf/1/

how to highlight the words which are invalid in input given by a user

how to highlight only the words which are invalid in input given by a user where i can make my custom invalid check function.
e.g
hello this is very good and very nice.
suppose this is the input by the user and suppose i want to highlight "very" and "this" or any other custom word.
I have tried putting html tag inside value but html does not parses inside value attribute of input tag.
Try using variable.split() in reading the input. Store it in array using loop and check for errors and highlight
You cannot simply put html tags in input. To enable "rich text" capabilities, you'll have to use the contenteditable HTML attribute, like so...
const words = [/(very)/gi, /(nice)/gi]
const highlightInput = () => {
const richInput = document.getElementById('rich-input')
let text = richInput.innerText
words.forEach(x => {
text = text.replace(x, '<span class="highlighted">$1</span>')
})
richInput.innerHTML = text
}
document.getElementById('highlight').addEventListener('click', highlightInput)
#rich-input{
border:1px solid #000;
padding: 5px;
}
.highlighted{
color:red;
text-decoration:underline;
}
<div>
<input type="button" value="Highlight!" id="highlight" />
</div>
<label>Enter your text below:</label>
<div id="rich-input" contenteditable="true">Hello this is very good and very nice</div>

Showing html text in FlowDocumentReader

I have a FlowDocumentReader control in my application.
<FlowDocumentReader Document="{Binding FlowDocument}" Style="{DynamicResource FlowDocumentStyle}" />
And here's how I set the text to the FlowDocumentReader:
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add("some <b>book</b>");
FlowDocument.Blocks.Add(paragraph);
The problem is that 'book' isn't shown like html, the tags are visible in the wpf application.
I tried using this converter:
http://code.msdn.microsoft.com/windowsdesktop/XAML-to-HTML-Conversion-ed25a674/view/SourceCode
but then the text shown in my wpf application looks like this:
<FlowDocument xml:space="preserve" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><Paragraph>some <Run FontWeight="bold">book</Run></Paragraph></FlowDocument>
and again it's not bold. How can I do this?
Use UI Elements to show formatted text and them to InlineUIContainer of Paragraph.
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add("some");
Label lb = new Label();
lb.FontWeight = FontWeights.Bold;
lb.Content = " Book";
paragraph.Inlines.Add(new InlineUIContainer(lb));
this.Doc.Document = new FlowDocument();
this.Doc.Document.Blocks.Add(paragraph);

how do i set property of text box to UpperCase

I use following style attribute so when i will start typing in text box suppose 'railway'then it should get enter in text box like 'RAILWAY' without pressing CapsLock
<input type = "text" class = "normal" name = "Name" size = "20" maxlength = "20"> <img src="../images/tickmark.gif" border="0" style='text-transform:uppercase'/>
but I am not getting desired output by using this attribute
The best method would be to change the styling on your form to display uppercase:
input.normal
{
text-transform:uppercase;
}
SEE EXAMPLE
However this will not actually convert the string to uppercase, just style it to appear this way.
Therefore then when the data is submitted, use whatever server side language to convert the string to uppercase for purposes of storing in the database etc. For example with .NET you would do:
str.ToUpper();
You can accomplish this using CSS, if you only care about stylistic aspect:
.normal { text-transform: uppercase; }
If you need the text itself to be in all-caps (which is probably what you meant, sorry), combine with a bit of jQuery (it can be done without jQuery, too, but what's the point in that?):
$('.normal').change(function() {
$(this).val($(this).val().toUpperCase());
});
Example: http://jsfiddle.net/HackedByChinese/QwSSe/1/
You need to put your text transform in your Input tag, not your Image tag. Like this.
<input type = "text" class = "normal" name = "Name" style="text-transform:uppercase;" size = "20" maxlength = "20">
<img src="../images/tickmark.gif" border="0"/>

Text on button in HTML

I have following code in HTML:
http://pastebin.com/GfrE1Pkh
I want to add text to banner_button_1 and banner_button_2. How can I do that?
Thanks!
This code is horrible, but I'll assume that you can not edit the HTML and just want to change it via JS.
var bannerButton = document.getElementsByClassName('banner-button')[0];
var bannerButtonLinks = bannerButton.getElementsByTagName('a');
bannerButtonLinks [0].innerHTML += "text for banner_button_1";
bannerButtonLinks [1].innerHTML += "text for banner_button_2";