SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,322
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    test bits of javascript in firefox somehow?

    i'm just starting out (finally) learning javascript. in a book i'm starting it says you can type single line experiment into the javascript console -- in firefox. i can't see how to do that. i'm wondering if my firefox version doesn't have this? i'm using firefox 2.0.0.14 on a mac. the book's date is aug 2006, and this version of firefox is dated 2007 so my firefox is newer than the book.

    how to run test bits of javascript by typing it into firefox?

    thanks.
    Last edited by johnyboy; Jun 15, 2008 at 04:40.

  2. #2
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Javascript test</title>
    
    <style type="text/css">
    div{float:left;width:45%;margin:1ex;min-width:400px}
    textarea{width:90%;border:3px #c0c0c0 ridge}
    </style>
    <script type="text/javascript">
    
    onload= function(){
    	var t1= document.getElementsByTagName('textarea')[0];
    	var t2= document.getElementsByTagName('textarea')[1];
    	var b1=document.getElementsByTagName('button')[0];
    	var b2=document.getElementsByTagName('button')[1];
    	
    	b1.onclick= function(e){
    		try{
    			var t=eval(t1.value);
    		}
    		catch(er){
    			t=er.message;
    		}
    		t2.value= t.toString();
    		
    	}
    	b2.onclick= function(e){
    		t1.value=t2.value=''
    	}
    }
    </script>
    
    </head>
    
    <body>
    <h1>Script Test</h1>
    <h2>Paste or type some code to test</h2>
    <p>
    <button >Test</button>
    <button >Clear</button></p>
    
    <div>
    <textarea id="ta_1" rows="20">
    // Test Code
    </textarea>
    </div>
    <div>
    
    <textarea id="ta_2" rows="20" readonly="readonly">
    Return value
    </textarea>
    
    </div>
    </body>
    </html>

  4. #4
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,322
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    ok great, thanks.

    i guess the thing the book was talking about has been dropped from firefox.

    thanks.

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    I have version 1.5 of Firefox and the Javascript Console lets you evaluate lines of code. Later versions with the Error Console behave differently.

    It should still be possible though to type into the addressbar
    javascript:alert('Hello world!');
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •