Formating in Alert Message with addition of image - javascript

Is it possible to achieve formatting of text in JS alert message?
<script>
function myFunction() {
alert("1.Enter your name. 2. Enter your mobile no. 3.Do not press back
button.");
}
</script>
I want these 3 messages to appear one below the other. I tried:
<p>1.Enter your name.</p><p> 2. Enter your mobile no.</p><p> 3.Do not
press back button.</p>
Didn't work. Also, wish to add this img src tag after the last message:
<img src="http://forums.nextgames.com/resources/emoji/smiley.png" alt="smily"/>
Thank you.

The alert box is a object, and not related to CSS. To do this style of thing you would need to create an HTML element and mimic the alert() functionality. The jQuery UI Modal box does a lot of the work for you.

try adding "/n" before the lines example "\n2", "\n3"

The browser alert box does not support rendering HTML, however you can use plain-text formatting like \n newline and \t tab.
alert("1.Enter your name.\n2. Enter your mobile no.\n3.Do not press back button.");

Related

Click button and get text with CeFSharp

I'm creating a program in vb.net to go to https://www.royalmail.com/track-your-item#/ and:
Enter some text in the Reference Number box
Click the button 'Track your delivery'
Grab the text from the page so I can search for the delivery date
I've had to switch to using CeFSharp, as the microsoft browser doesn't want to load the page, so this is my first time with it.
This is what I have so far (CWB1 is the name of the browser object):
CWB1.LoadUrl("https://www.royalmail.com/track-your-item#")
CWB1.LoadUrl("javascript:void( document.getElementById( 'barcode-input' ).value='12345678' )")
Dim script = "var pagebutton = document.getElementById('submit');
pagebutton.click();"
CWB1.ExecuteScriptAsyncWhenPageLoaded(script)
The page loads, the text '12345678' is entered in the search box, but running the script to press the button does nothing.
I can't figure out how to press the button. I thought it must be the wrong id, but inspecting the web page seems to give button id="submit" so this should work? I've tried a few variations but nothing seems to move me forwards.
I also then need to grab the text from the page - not sure how to so this either?
Thanks for any help!
OK, I've found that the button press only works if you enter the text in the field via sendkey event. So the button press code was working after all - I guess the site's security is trying to make sure someone is typing the text in, instead of a robot. Thanks for your help with this amaitland!

Keeping text entered into a textarea visible at all times

When entering text into a textarea manually, it remains visible at all times. However I'm using a simple javascript function to enter some text when an icon on the page is clicked.
onClick="addline('xyz')
function addline(sometext)
if(sometext == "xyz")
{
document.getElementById('thearea').value = "Hello world!\n";
}
The problem is, when text entered this way reaches the bottom of the textarea, it disappears from view and the scrollbar just lengthens.
My question is, is there any way to keep the text visible at all times? Thanks.
Thank you for referring me to a similar request for assistance. I have done what I thought was a comprehensive search here and on other web sites to a solution to this issue before posting. Unfortunately, the code suggested doesn't make any difference, the text added using the above function remains hidden in my textarea until the scrollbar down arrow is clicked.

Get User Comments from a Prompt Box also on Cancellation

I am building a HTML application (with Javascript, CSS). It is an user-interaction based application. I have a requirement where the user gets a prompt box with option to enter his/ her comments and to either accept (OK) or reject (Cancel) the action. When the user accepts (OK) i can read the user-comments. However, I also want capture the user comments when the Cancel button is pressed.
Most of the examples which I saw (either using custom box or window.prompt) only read the inputs on OK but nothing on cancel. Also as per window.prompt definition it does not read the comments box on cancellation. How can this be achieved?
if (alertInfo.indexOf(checkString) > -1){//check if a string is present in the message
var showPrompt = window.prompt("Please enter your remarks", "");
if(showPrompt != null){
userAccepted(showPrompt);
}
else{
sendRejection();// This is where I also need to read the user comments
}
}
else{
//reload the page
}
You're trying to misuse the feature. Cancel means cancel, not "OK but do something else". That's why you can't do this.
You'll have to find another way, such as rendering your own <form> to obtain the comments.
As #Lightness Races in Orbit said, you simply can't do it with the windows prompt. You have to make a floating div and make it visible instead of the windows prompt.
You can have radio buttons that requires the user to accept or decline, a text box to enter comments and a single OK button to close the dialog ("basically hiding the DIV").
Instead of a floating div, the user was directed to a new page where he / she could enter the inputs and either accept or reject the action. The advantage of having a separate page is that the user does not have to zoom-in / out the page to properly view the contents.
Thanks.

javascript focus function not working as expected

I am having a jsp/html page.This page is accessed from two different links.
It is Menu1-->demo.html page and from Menu2-->demo.html page(In my case its jsp)
In the demo.html page I am having a text box which is disabled by default.
<input class="mytextinputtextField" type="text" id="countryOfOrigin"
readonly style="background-color:#DCDCDC" />
Now when the demo.html page is accessed from Menu2 , I am checking it using a hidden parameter and again enabling the text box and setting the focus on the text box.
if(document.getElementById("submenu_name").value=="PM")
{
document.getElementById("countryOfOrigin").focus();
}
The field is enable and the cursor is visible but if I type the text is not typed in the text box.
I need to click on the text box to enter the text.
I think it is because of the disabled and again enabling the field .
Please can any one help me to be able to type in the text box on the focus event from javascript.
I am not using JQuery and the browser is I.E 6
Try this :
document.getElementById("countryOfOrigin").removeAttribute('readOnly');
jQuery version :
jQuery('#countryOfOrigin').removeAttr('readOnly');
Have you tried removing the attribute?
document.getElementById("countryOfOrigin").Attributes.Remove("readonly");
or
document.getElementById("countryOfOrigin").removeAttribute("readonly");
Thank you for your help.
I hav found solution or may say work around.
I am pasting the code which may be useful for others
if(document.getElementById("submenu_name").value=="PM")
{
document.getElementById("countryOfOrigin").focus();
document.getElementById("countryOfOrigin").select();
}
Here is an unofficial solution, we have to use the setTimeout() function to delay the focus() execute time.
setTimeout(function() { document.getElementById('myInput').focus(); }, 10);
See http://www.mkyong.com/javascript/focus-is-not-working-in-ie-solution/

How can I display an error message via JavaScript?

I'm creating a form, and I'm validating it with JavaScript. The way it works now, is if a value is not correct, it displays an alert stating that you need to enter text. My question is, how can I change it so that instead of an alert, the text box will turn red, and something like: "This is required" will show next to the textbox. I think I can solve this with jQuery, but I was wondering if anyone had any suggestions. THANKS!
P.S. If you go to yahoo.com, click Sign Up, and click Create Account (without entering anything), you'll see what I'm aiming at.
You could create a CSS class with the following properties:
input.ERROR { border-color: red; }
Using jQuery, you can add this class to the input box with the incorrect value:
$("input[name=Address]").addClass("ERROR");
(assuming the input box with the name "Address" had the wrong value)
Well , I would use a jQuery Validation plugin which is at
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
You just need to add the css class "required" to the elements that you need to be validated

Categories

Resources