I know how to insert line breaks in a JavaScript alert (using '\n'), but how do I prevent them - that is, make the text remain on the same line within the alert.
I have a message I want to display that breaks on the last word of the sentence, leaving a very awkward looking message. So, for example, instead of this:
Please ensure proper text is entered into the form
The users sees this:
Please ensure proper text is entered into the
form
...quite unappealing.
I know I could alter the message to possibly make it shorter, but for future reference, I thought I would ask the question.
This isn't possible, because the styling of the alert dialog that appears depends completely on the browser's implementation. Different screen sizes and different browsers will enforce different maximum / minimum widths on these dialogs. Even shortening your text won't guarantee that it is restricted to one line on all browsers.
Your best solution would be to implement a JavaScript dialog of your own.
Javascript alerts are not customisable in this fashion because they are completely dependent on the browser itself. Consider using an in-DOM modal.
Unfortunately, there is no way to make the "alert" window wider, which means text that doesn't fit will wrap to the next line. I would suggest displaying the message in HTML instead.
Related
For a small web app I need to get the screen size of multiple displays. First I tried it with simple javascript via screen.height but that only works for the primary display, no matter where the window was.
I was going to do a fallback with inputs anyways but i wanted an automatic way, too. I was looking for a way via actionscript but couldn't find anything.
I don't want something where the user has to click accept or anything like that. Just something that works without asking the user or when it doesn't using the fallback method (in this case just do nothing and let the user fill in the size himself)
Do you know any method?
Greetings
How do I make ASP.net labels display dynamically, that is, they should not take up any whitespace when not being used.
I have a good chunk of error message labels at the bottom of a form, which are set to remain hidden until the user makes an error on one of the text boxes (does not pass validation). This works, and they remain hidden; however, they still take up their respective white space, which causes the form to look goofy and unprofessional since there is a huge chunk of whitespace in the middle of the page.
I would like to make them appear, and only take up space, as needed, hopefully setting them to appear either in javascript or my vb.net codebehind. Creative solutions are welcome.
Sorry if this is a google-it type question, I did make an earnest effort to find it online and my googlefu was not strong.
A good control to use for validation messages is the validation summary control. In your code behind you can add your own errors as well as some automatic validations (i.e. required fields, etc)
I think the best way is to replace asp.net label with literal and wrap the literal with div. Then, you can hide or show the div. You won't need br tag.
I am working on a page which will have an area at the bottom listing out groupings of FAQs with a few different tab levels and then questions which can be expanded/collapsed by the user. We want to provide a way for the user to be able to nicely print
Just the questions/answers they have expanded
All the questions/answers in the sub-group they have selected
All the questions/answers in the primary group they have selected
All the questions/answers on the page
The plan is to have a drop down box with a print button (unhidden by Javascript) that would apply a class that when clicked that would hide the other content on the page and give us the display we want for the user selected option. This is all easy enough to do and we can apply a default print-style using #4 as a catch-all when javascript is disabled which can just be triggered via the normal print mechanism.
The problem is how to remove that special style when the printing is done so that if the user were to go and click the browsers print button, they get what they expect a print out of the whole page instead of the last selected "special" print view.
I have thought up a few potential solutions but I am not entirely happy with any of them:
We could replace our planned in page print with a link to another page which formats itself without interfering with the rest of the page content. I don't like this idea because it breaks the page into pieces and if possible I always prefer to keep the user on the page.
We could set a timeout when the print button is clicked to remove our special class after some period of time bringing the page back to a default state. I don't like this because it will produce unpredictable behavior from the user's point of view. If they take "too long" printing the first time they don't get the style they want. If they print the whole page "too quickly" after the special print they get an odd result
We can use the after-print trigger in IE to remove the style for those users, but as far as I can tell this sollution is only an option in IE and leaves all the other browsers in the cold.
We could make a general assumption that a user is very unlikely to come to the page and do a special formatted print followed by a desire to print the entire page and just let is go at that.
Any other solutions anyone can think of?
Your first solution is actually very good if you use target="_blank". This would keep the user on the page but avoid all the other problems.
However, I think the whole problem is moot if you make the page layout match the dropdown. In other words, if they're looking at Section 2, Subsection 3, Question 1, and they select
"print all questions in subsection", just expand the subsection and open the print dialog box. Then you only have to worry about setting a single class (noprint) and apply it to everything else.
Hello guys
I know that is probably a stupid question but i had to be sure after all.
Can i add an input of type password in a prompt box?
prompt box is a one of javascript's Popup boxes.(Alert,Confirm and Prompt)
No, you can't.
The popup is browser controlled and can't be changed.
As the documentation shows, you can only supply a message and default text.
You can use javascript to create your own overlay that simulates a prompt popup.
See the jQuery UI Dialog for ideas and examples.
If you literally mean the prompt function, you can't. What you can do instead is pop up a div or similar above the main content of your page (using absolute positioning and a z-index value) and put the password box in there.
More in the various answers to these questions:
How to have a JQUERY POPUP window by using only JQUERY (without other extra JS)
Making a Javascript Yes/No Confirmation Box?
There are a variety of libraries you can use that will do the hard work for you (not that it's that hard, but still). If you're already using a library like jQuery, Prototype, YUI, Closure, or any of several others, you may find that there's a plug-in designed for use with that library (jQuery UI for jQuery, for instance). If not, there are plenty of stand-alone implementations. Look for "light box" or "lightweight window" or "JavaScript dialog box", etc.
Note that any of these will require a bit of a change to the logic of your code, since prompt brings the browser and your script to a screeching halt until the prompt is dismissed by the user, whereas this mechanism of flying an element over the top of the content is, by its nature, asynchronous.
With alerts you can have text inputs. I was hoping you could put check boxes in. Is this possible?
http://www.w3schools.com/JS/js_popup.asp
No, you would need to build out a dialog box in order to achieve this.
You are able to achieve this with relative ease through jQuery and more specifically the jQuery UI plugin, allowing dialog boxes to come up without too much know-how
No. The only options are:
alert (display string);
confirm (display string and get yes/no|true/false back);
prompt (display string and get input string back)
You can create your own modal dialog using a variety of techniques. Under the hood, they all essentially do the same thing - display a separate web page in a popup window or iFrame and disable input access to the rest of the browser until the popup is closed. These are pretty easy to get wrong (hard to use + very annoying) but when done right they offer the developer a lot of power - since it's a complete web page you control, you can pass complex JavaScript objects between the dialog and the main browser window, instead of having to rely on the primitive interaction modes offered by the out-of-the-box dialogs.
Pretty shure it isn't possible. However, you can simulate a "alert box" with the contents you need. JQuery, for example, is a great javascript framework to achieve that.
no, but you can create a function that opens a alert box with html in it, like on facebook.
No, but you can create functions with alert boxes.
javascript:alert("Hello");
javascript:confirm("Hello");
javascript:prompt("Hello");
are the inly available ones.