SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member CybJunior's Avatar
    Join Date
    Dec 2005
    Location
    fgfg
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    click paramteres

    What parameteres can be passed to click() function?
    Can i pass coordinates of the button that should be pressed?

    Something like document.body.click(50,100);
    but that actualy is not working....

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your button has an ID you can do
    document.getElementById("myButton").click();

  3. #3
    SitePoint Member CybJunior's Avatar
    Join Date
    Dec 2005
    Location
    fgfg
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, but i don't know the button's id. i only know its coordinates... is it possible?

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    suppose if you really wanted to, you could loop through all button's (getElementsByTagName) and check each one to see if the coordinates match, thus giving you the button.

    Why are you tring to emulate a button click?

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    
    <script>
    function clickButton(x, y)
    {
    	var elements = document.getElementsByTagName('INPUT');
    
    	for(var i = 0; i < elements.length; i++)
    	{
    		if(elements[i].type == 'button')
    		{
    			if(elements[i].offsetTop == x && elements[i].offsetLeft == y)
    			{
    				elements[i].click();
    				return;
    			}
    
    		}
    	}
    }
    function listButtons()
    {
    	var elements = document.getElementsByTagName('INPUT');
    
    	for(var i = 0; i < elements.length; i++)
    	{
    		if(elements[i].type == 'button' && elements[i].id != 'findButton')
    		{
    			alert('x: ' + elements[i].offsetLeft + '\ny: ' + elements[i].offsetTop);
    		}
    	}
    }
    
    window.onload = listButtons;
    
    </script>
    </HEAD>
    
    <BODY>
    
    <input type="button" onclick="alert(this.value);" value="1" /><br />
    <input type="button" onclick="alert(this.value);" value="2" /><br />
    <input type="button" onclick="alert(this.value);" value="3" />
    
    <br />
    <br />
    x<input type="text" id="yVal" />
    y<input type="text" id="xVal" />
    <input type="button" id="findButton" value="findButton" onclick="clickButton(document.getElementById('xVal').value, document.getElementById('yVal').value);" />
    
    </BODY>
    </HTML>

    It will first list the coordinates of the three buttons, then it will allow you to type in the coorinates ie 10x15 and click findButton.

    It will then search all three buttons for those coordinates and then click the button that it found.



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
  •