SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    frame and javascript

    This code works but the document.getElementById('table1').onclick = 'nextpage.php?x=' + x + '&y=' + y;

    dosnt work how would i get it to work?

    Code:
    <table border="1" width="100" height="100" id="table1">
    	<tr>
    		<td><script language="javascript" type="text/javascript">
    document.onclick = function(e){
    		var e 		= e ? e : window.event;
    		var x = e.screenX;
    		var y = e.screenY;
    		document.getElementById('table1').onclick = 'nextpage.php?x=' + x + '&y=' + y;
    	}
    </script></td>
    	</tr>
    </table>
    Animated Chatrooms - www.121chatrooms.net

  2. #2
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone?
    Animated Chatrooms - www.121chatrooms.net

  3. #3
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is another code i got still not working

    Code:
    <table id="table1" border="1" width="100" height="100">
    	<tr>
    		<td><script language="javascript" type="text/javascript">
    document.onclick('table1') = function(e){
    		var e 		= e ? e : window.event;
    		var x = e.screenX;
    		var y = e.screenY;
    		document.location = 'nextpage.php?x=' + x + '&y=' + y;
    	}
    </script></td>
    	</tr>
    </table>
    Animated Chatrooms - www.121chatrooms.net

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Most browsers have now prevented the location bar from being changed from javascript.

    Please explain what you are wanting to achieve.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i need it in a table so when i click part of inside the table i want to output the same coordiantes as i would on any monitor size, beacause if i click the same area on 2 different kinds of monitor sizes it outputs as different sizes depending on the page.
    Animated Chatrooms - www.121chatrooms.net

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    If this is for testing purposes there are much better ways.
    For example, Firefox has a brilliant extension called Firebug that lets you use console.log() in scripts

    Our you can get the web developer toolbar, a part of which lets you select different objects in the page (tables included) and show you details about it including positioning and sizing information.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im making an animated chat script so where i click on the page the users avatar moves to that coordinate but on each monitor size the coordinates are different so i need them in a table and the table has a certain amount of pixels so the coordinates are the same on all monitor sizes.
    Animated Chatrooms - www.121chatrooms.net

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Try the following

    Code JavaScript:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    	<title>Table test</title>
    </head>
     
    <body>
    <table id="table1" border="1" width="100" height="100" onclick="locationRefresh(event)">
    	<tr>
    		<td></td>
    	</tr>
    </table>
    <script type="text/javascript">
    function locationRefresh(e) {
    	e = e || window.event;
    	var x = e.screenX;
    	var y = e.screenY;
    	document.location = 'test.htm?x=' + x + '&y=' + y;
    }
    </script>
    </body>
    </html>
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your a legend!
    Animated Chatrooms - www.121chatrooms.net

  10. #10
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Ta, there's a better way too that doesn't leave javascript strewn about in the midst of the HTML code.

    Get rid of the onclick attribute from the table element

    Code HTML4Strict:
    <table id="table1" border="1" width="100" height="100">

    And attach the event after the function with one of the following lines, depending on which is more appropriate

    Code Javascript:
    document.getElementById('mytable').onclick = locationRefresh;

    or

    Code Javascript:
    document.getElementsByTagName('table')[0].onclick = locationRefresh;

    or if you want to use a temporary variable

    Code Javascript:
    var tables = document.getElementsByTagName('table');
    tables[0].onclick = locationRefresh;

    or you can even place it inside of an anonymous function to ensure that the variable doesn't hang around afterwards

    Code Javascript:
    (function () {
        var tables = document.getElementsByTagName('table');
        tables[0].onclick = locationRefresh;
    })();

    This traditional method of attaching an event is better than the previous inline technique. There are other more advanced ways that are great for when you want to attach multiple events, but this traditional method is very good for the task currently at hand.
    Last edited by paul_wilkins; Jan 20, 2008 at 03:38.
    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
  •