How to get text from javascript alert box
Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
-
JanMolendijk
- Posts: 248
- Location: Holland Rotterdam
How to get text from javascript alert box
Good evening (dutch-time) I have a javascript what can copy text to a clip-board + it has a button to show the item-list in a alert-box.
But can`t find out how I can select the text from the alertbox.
Hope you can help me out.... ?
Code: Select all
<body>
<table WIDTH="100%" BORDER="0" CELLSPACING="5" CELLPADDING="5">
<td align="center">
<table width="100%">
<tr>
<td WIDTH="100%" align="center"><form name="history">
<p><font
face="ARIEL,HELVETICA" SIZE="-1"><input name="command" type="text" value size="20"> <input type="button"
value="Add to List" onclick="f_store(document.history.command.value)"> <input
name="history" type="button" value="Show List" onclick="f_print()"> </font> </p>
</form>
<p align="center"><font
face="ARIEL,HELVETICA" SIZE="-1"><script language="JavaScript">
<!-- hide it ...
function MakeArray( n ) {
if( n <= 0 ) {
this.length = 0;
return this;
}
this.length = n;
for( var i = 1; i <= n; i++ ) {
this[ i ] = 0;
}
return this;
}
var history = new MakeArray( 15 );
var index = 0;
var cmmnd = 1;
function f_store( sTR ) {
var i;
if( index >= history.length ) {
for( i = 1; i < history.length; i++ )
history[i-1] = history[i];
index = history.length - 1;
}
history[ index ] = cmmnd + ":" + sTR;
++cmmnd;
++index;
document.history.command.value="";
}
function f_print() {
var allCmmnds, i;
allCmmnds = "";
for( i = 0; i < index; i++ )
allCmmnds += history[i] + "\n";
alert( allCmmnds );
}
</script>
Admin
Hello,
You cannot get /copy the text directly from the alert box, but you can get the text (value) from the variable that is added in the alert() function.
So, identify in the javascript code where the text come from, the variable that store the text, and you can get the text from that variable.
In your code, the text is stored in the "history" variable, which is an array. You can get the text you want from that array.
Try study the f_print() function in your code, which contain the alert() instruction.
JanMolendijk
Thanks for the support I tried already things with history + f_print
also studied those a little before I asked coursesweb but I shall
when my head is cleared do those staps again.
(vv sorry for my late response incase)
Similar Topics
-
Javascript add different text to each minute of hour
JavaScript - jQuery - Ajax
First post
Hello Coursesweb I`m unknown with javascripts ????
I would like to add function minutes to this script
on each minute an diferent text added to...
Last post
Hello,
Try the following script.
<div id='addtxtmin' style='color:#00d; font-size:20px; font-weight:700'></div>
<script>
const...
-
Adding content from a Div into an input text field
JavaScript - jQuery - Ajax
First post
I still don`t understand how I can get the results from a div into a text input form field ?
<div id= div2 > Content </div>
I...
Last post
Thanks Chief for all your support....
My URL-extractor is working
in the comment-system
-
Reverse the characters added in text field
JavaScript - jQuery - Ajax
First post
I have the following html and JavaScript code. An input text box and a button.
<input type='text' id='backwards-input'>
<button...
Last post
Try use and study the following code:
<input type='text' id='backwards-input'>
<button id='backwards-button'>Button</button>...
-
Hide element if data contains specific text
HTML - CSS
First post
Is there a possibility to hide HTML elements if the 'data-' attribute contains a specific piece of text?
For example: Hide the Divs that it's data...
Last post
You can do this with either CSS or Javascript.
CSS:
/* with specified elements */
div {
display: none;
}
/* or global */
{
display: none;...
-
Textarea with buttons for format text and smiles
Scripts from this website
First post
I`m a bit furter with my comment + badword-filter & hashtag-system
But my problem I can`t see the bbcode I only see HTML tags into my textarea...
Last post
In the archive with that JS script there is a file form.html. In that file there are instructions and a demo with textarea and bbcode.
Open that...