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.
User avatar
Posts: 274
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

  <td align="center">
  <table width="100%">
    <td WIDTH="100%" align="center"><form name="history">
    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>
    <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;
function f_print() {
var allCmmnds, i;
allCmmnds = "";
for( i = 0; i < index; i++ )
allCmmnds += history[i] + "\n";
alert( allCmmnds );


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.

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