How to display underline in javascript string? - javascript

I have the following javascript code:
var result = ("Please enter your name","Andrew");
and i wanted to underline the word "name" in the above message.
This is trivial but i have no clue after searching for escape code representation for underline. Or is the above possible in javascript ?

If the example code given had a typo and should've read like this:
var result = window.prompt("Please enter your name","Andrew");
then the answer is that you can't format the text or change the labels on the buttons or anything. This applies to the built-in alert() and confirm() as well as to prompt().
It's a bit more work, but you can implement your own equivalent dialog by building one from HTML using a transparent <div> to cover the rest of your page so that users can't interact with the rest of the page until the dialog closes. (Or use a translucent <div> to make it more obvious to the user that the rest of the page is "disabled".)
I would not bother coding this from scratch when there are lots of JS libraries that do it for you. The jQuery dialog is pretty easy to use, to name just one option.

If this is ending up on a web page you should just be able to use:
var result = ("Please enter your <u>name</u>","Andrew");
...but I'm not exactly sure what it is you're intending to do. Can you add more detail to your question?

var result = ("Please enter your <u>name</u>","Andrew");

Related

Is it possible to manually edit data after a dropdown auto-populates the field?

I am the opposite of a code monkey, so please forgive me if this is a simple solution. I have searched and searched and though I've found possible code examples, cannot find any information on how to fix the issue.
I've created a form-fillable PDF. I have fields that calculate based on inputs. I have a dropdown box that auto-populates some of the numbers (to add to the manual inputs). All of these work great!
I thought I would get fancy and further fill some of my data in the form. This is where the problems get funky.
I am setting the fields as shown, but those numbers can no longer be modified afterward.
this.getField("RanksPsy").value = psy;
this.getField("RanksBlade").value = blde;
this.getField("RanksBrawl").value = brwl;
this.getField("RanksCou").value = cou;
this.getField("RanksDip").value = dip;
I have buttons to increase/decrease the Ranks... fields, but the dropdown locks them and I'd like to avoid that if possible.
Is there another way to set those fields without using this.getField?
Thank you.
If I'm honest, I didn't understand the question well 😅
I don't recognize the getField function, so I decided to google it and found a RAD PDF documentation, so I'm assuming that's the library you're using to do this.
As that documentation states,
getFunction gets the first PDF form field object in the loaded
PdfWebControl document with a given name.
And this is the example provided, it may help.
var field = myApi.getField("Test Name");
if(field) {
//set its name to "New Name"
field.setProperties( {"name" : "New Name"} );
}
The solution to this is to put the script as an 'on blur' event rather than a keystroke event. It writes the data and then leaves it alone, which is exactly what I was looking for.

Fill a Textbox with a Link?

i have a link and i want to prepare it so that i fill a textbox with a value.
This is the link http://www.lolking.net/ and i want that if a always go to this site they fill the texbox where is write ("Summore name...").
How i can make this? Must be write a script for the site ? Or can i prepare link to fill this textbox?
This question is for all site where is a textbox, i get the name of the textbox with F12 and i want to prepare all links how i fill textbox
Greetz
You could reasonably write a Chrome extension which does this. You'd have to add logic for each site that you want it to work on, but actually replacing the text in that box (I assume that you want it to automatically search for your summoner name) is as simple as this one line:
document.getElementsByName("name")[0].value="<YOUR SUMMONER NAME>";
But that example will only work on lolking.net. To make it more general, you would replace "name" in the following way:
document.getElementsById("<INPUT ID>")[0].value="<REPLACEMENT TEXT>";

HTML tags in prompt (JavaScript) [duplicate]

I'm using JavaScript's prompt() function.
var favorite = prompt('What is your favorite color?', 'RED');
I'm using IE 7 and the prompt box that opens has a title bar that says : 'Explorer User Prompt' and further text that says 'Script Prompt:' Then beneath this is my text : 'What is your favorite color?' Also the 'OK' and 'Cancel' buttons appear in the far right side of the prompt box and the text entry box appears at the very bottom of the dialogue.
Is there any way to change the title bar, remove the text 'Script Prompt', and put the OK and cancel buttons beneath the text entry box?
Yes. By not relying on browser UI (which is actually disabled by default in some browsers) and instead making your own.
All it takes is a simple modal dialog with a form in, and you're all good. The only downside is that it won't be blocking anymore (if you can consider that a downside), so you need to put the rest of the code inside a callback that the prompt calls when it's closed.
No I don't believe so. The problem was that people would use prompts maliciously so microsoft added that to make it look more like it was a page specific prompt and not a IE prompt.
You can do an in page dialog with jQuery or something:
http://www.abeautifulsite.net/blog/2008/12/jquery-alert-dialogs
Short answer: no.
Longer answer: No, but you can roll your own popups with jQuery's UI library or by hacking up something with the DOM yourself.
No, there isn't.
The closest you can come is to mock up a fake one using DOM elements.
Not exactly what's being asked, but the only way I found to give the prompt box some formatting...
Using this answer, this answer and these HTML symbols, one can get creative and achieve this:
Demonstration:
var balls = '\u25CD'.repeat(24),
blue = '\u27BF',
red = '\u274C',
yellow = '\u2728',
green = '\u2705',
arrow = '\u25B8';
window.prompt(balls+' \u25C9 '+balls+'\rWhat is your favorite color?\r\t'+arrow+' B\u0332lue '+blue+'\r\t'+arrow+' R\u0332ed '+red+'\r\t'+arrow+' Y\u0332ellow '+yellow+'\r\t'+arrow+' G\u0332reen '+green);

Autofill Text box on a Web Page (Javascript/VBScript)

I really need to know how I can autofill text boxes on a web page.
What I really want to achieve is the following:
1) Go to http://show.websudoku.com
2) Replace all the empty cells with a 0 (zero).
Is that possible?
To fill the empty spaces of the Sudoku grid at http://show.websudoku.com with zero's, here is some JavaScript to do that. It is formatted for use as a "Bookmarklet":
javascript:(function(){var x,k,f,j,r;x=document.forms;for(k=0;k<x.length;++k){f=x[k];for(j=0;j<f.length;++j){r=(f[j].className.toLowerCase()+f[j].type.toLowerCase()+f[j].value);if(r=="d0text"){f[j].value="0";}else if(r=="d0text0"){f[j].value="";}}}})();
The setup:
Create a new Bookmark/Favorite. For now, the URL for the favorite can be anything. An easy way to do this is to drag ANY link/url from the browser address bar, or any web-page link, to the "Favorites Bar" or to the Bookmarks/Favorites sidebar.
Select the new favorite, and rename it to any name you like.
Copy the JavaScript code from above to the clipboard. It must remain as 1 continuous single line, and it must begin with "javascript:(" and end with ")();"
Edit the properties of the new favorite.
Remove the "URL" that is currently in the favorite and replace it by pasting in the JavaScript code from above, into the "URL" text field for the favorite, then save the changes.
To use the bookmarklet:
From the browser, navigate to http://show.websudoku.com as you normally would.
Click the new favorite (Bookmarklet) that you just edited.
All empty spaces in the Sudoku grid will be filled with 0's. Click the new favorite (Bookmarklet) again, and the 0's will be removed leaving empty spaces once again.
Here is what the Javascript code looks like expanded, with indents:
javascript:(function(){
var x,k,f,j,r;
x=document.forms;
for(k=0;k<x.length;++k){
f=x[k];
for(j=0;j<f.length;++j){
r=(f[j].className.toLowerCase()+f[j].type.toLowerCase()+f[j].value);
if(r=="d0text"){
f[j].value="0";
}
else if(r=="d0text0"){
f[j].value="";
}
}
}
}
)();
* Spoiler alert *
In case you want to "cheat", the JavaScript here will "solve" the Sudoku:
javascript:(function(){var x,k,f,j,ecl,etl,en,ev,s,e,c,d,dl,dr,n;x=document.forms;for(k=0;k<x.length;++k){f=x[k];for(j=0;j<f.length;++j){e=f[j];r=(e.name.toLowerCase());if(r=="cheat"){c=e.value;break;}}for(j=0;j<f.length;++j){e=f[j];ecl=e.className.toLowerCase();etl=e.type.toLowerCase();en=e.name;ev=e.value;if(etl=="text"){if(ecl=="d0"){dr=en.substr(en.length-1,1);dl=en.substr(en.length-2,1);d=(((Number(dr)-1)*9)+Number(dl))-1;n=c.substr(d,1);if(ev.length==0){e.value=n;}else{e.value="";}}}}}})();
Setup and use is the same as described above.
While it's not much fun to solve it like that (OK, maybe it's a little fun the first couple times), and definitely not challenging, if you are in a real-real-real hurry, you can solve it in 1 click.
Note: I have only tested these 2 bookmarklets with IE9.

RTL text in Facebook posts re-orders words

I am from Tunisia, and am currently developing a PHP script called PHPFOX. In it, I want to integrate an ability to change the text-direction of a TextBox automatically. Specifically, when you go to Facebook and want to leave a comment, the TextBox's input direction will change based on what your chosen keyboard direction is.
In other words, if you have chosen the Arabic language for your keyboard, the TextBox automatically gets set to RTL direction.
Here is the code I'm using so far:
$('input').keyup(function() {
$this = $(this);
if ($this.val().length == 1) {
var x = new RegExp("[\x00-\x80]+"); // ASCII
//alert(x.test($this.val()));
var isAscii = x.test($this.val());
if(isAscii) {
$this.css("direction", "ltr");
} else {
$this.css("direction", "rtl");
}
}
});
Everything works fine for input. However, look what happens when I input a mixed LTR and RTL sentence in my site, then post it to Facebook:
Here is what I enter:
Here is what appears on Facebook:
See the difference? How do I solve this?
First off - the approach you're taking is brilliant, and I applaud you for it. Switching the direction of <input> via CSS to allow natural typing makes a huge amount of sense.
The reason your OUTPUT is coming out strangely, though, is due to the generated content which you are sending to Facebook. My guess is that since the last few characters of your text are in RTL, your input's CSS is still set to RTL.
Consider this example (result can bee seen here):
<div>
<b>LTR:</b> <span dir="ltr">This is some الفبای فارسی text</span>
<br /><br />
<b>RTL:</b> <span dir="rtl">This is some الفبای فارسی text</span>
</div>
Because the second <span> is displayed with dir="rtl", the text winds up getting re-ordered, with each LTR phrase treated as a single RTL "word".
What you might consider trying, in your example, is simply making sure that prior to submitting the post, you set your CSS direction back to LTR, which will produce the result I think you're looking for.
If you are interested, here is a blog post discussing the difference between HTML and Plain-Text style rendering of LTR and RTL text. It doesn't provide you any answers, but will point out more details about the problem itself.

Categories