Nov 25, 2006 9:53:36 GMT -5
Lets get started.How would I put text into an HTML document using Javascript?<script type="text/javascript">
<!--
document.write("Text here");
//-->
</script>
Just make sure you place a semi-colon after each line of your code. Do not forget, your text
must be enclosed by a set of quotations, whether you would like to put a single (') or a double (") they will both work. If you do not surround your text in quotations, the will not be executed.
Strings[/b]
A string is anything that is in between quotations. They are shown and ran or excuted. This means they have no special values.
document.write("document.write()");
Then the
document.write( ) statement in quotations, won't end up holding the same amount as the actual
document.write( ). It will be displayed as a string. In this case, think of strings as sentences, they are shown or displayed exactly the way they are written.
document.write("Did you "Play video games"?");
In this case, you needed to place one more quotation inside quotations. Just to prevent an error that could happen, place a backslash (\) before each quotation.
document.write(\"Have you played \"Video games\"?");
Pop-up Boxes : Alerts, Prompts, and Confirmations[/u]
-------
<script type="text/javascript">
<!--
alert("Alert Text Here"); // this is our alert
//-->
</script>
-------
The red is how you can distinguish what type of pop-up is indicated. The string (PopUp Text Here) is indicated just as it is shown here, as I have told you many times. Wherever you place this simple script whatever is in the designated string spot, will appear in the popup box.
-------
<script type="text/javascript">
<!--
prompt("Request","Input"); // this is our prompt
//-->
</script>
-------
Once again, the red indicates that this is a Prompt. Prompts are a little harder to understand than Alerts, just for the fact that they have
two parts. The request, and the input. The request is what you want to ask the user, such as a question. Both of these area's can be left blank. Once again, strings are the same as sentences, and are displayed the way they are written.
-------
<script type="text/javascript">
<!--
confirm("Confirmation Text"); // this is our prompt
//-->
</script>
-------
This type of popup is a confirmation. It is simply a statement, with the buttons "Ok" and "Cancel" The effects of Ok, are the exact same as clicking Cancel, all that happens is the box goes away. Whatever is in the quotations, will be displayed. "OK" and "Cancel" are default in this script, do not add them yourselves.
May 16, 2007 14:59:52 GMT -5
is there any way to make the alert thing like only come up once per user unless they erm delete cookies or whatever?
im using mine on the forum but its only on one board. Just whenever people go to post and stuff it pops up AGAIN
May 17, 2007 3:43:29 GMT -5
Then you have to look if there's the cookie, if not alert and set the cookie.
May 17, 2007 16:00:30 GMT -5
-------
<script type="text/javascript">
<!--
confirm("Confirmation Text"); // this is our prompt
//-->
</script>
-------
This type of popup is a confirmation. It is simply a statement, with the buttons "Ok" and "Cancel" The effects of Ok, are the exact same as clicking Cancel, all that happens is the box goes away. Whatever is in the quotations, will be displayed. "OK" and "Cancel" are default in this script, do not add them yourselves.
Slight correction, if you say
var whatever = confirm("Yes or no?");
Then it'll store a boolean true if they say yes, or false if they cancel.
Jun 11, 2007 21:09:42 GMT -5
-------
<script type="text/javascript">
<!--
confirm("Confirmation Text"); // this is our prompt
//-->
</script>
-------
This type of popup is a confirmation. It is simply a statement, with the buttons "Ok" and "Cancel" The effects of Ok, are the exact same as clicking Cancel, all that happens is the box goes away. Whatever is in the quotations, will be displayed. "OK" and "Cancel" are default in this script, do not add them yourselves.
Slight correction, if you say
var whatever = confirm("Yes or no?");
Then it'll store a boolean true if they say yes, or false if they cancel.
You don't have to "store" it to return it.
alert(confirm("Y, N?"))
Jun 15, 2007 15:05:08 GMT -5
Didn't think of it like that. Guess you could just put it in an if at some point and use it to execute the code.
if(confirm("Proceed?")){
//proceed
}
Not that one ever uses them much, but meh.
Jun 15, 2007 18:34:24 GMT -5
We go to meetings and use cheat sheets.
Jun 17, 2007 8:43:59 GMT -5
how come i've never been invited to any meetings? ;'(
and nice tutorial.