Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > calling another events onclick ...

Reply
Thread Tools

calling another events onclick ...

 
 
phish.guy@gmail.com
Guest
Posts: n/a
 
      08-11-2006
How do I call another event's onclick function from a button press? I
have stored information dynamically created in a div onclick function
that is not accessible directly by the button, but i need to call the
onclick for the specific div.

my code looks like this:

<div id='field_1' onclick='divclick(this, *(field1 specific data*))'
....> ...</div>
<div id='field_2' onclick='divclick(this, *(field1 specific data*))'
....> ...</div>

<input id="doclick" type="button" value="value" onclick='nextMove()'/>

now, either field 1 or 2 is 'active' so i keep that stored in
javascript as

var current; //lets say it is pointing to 'field_1'

function nextMove()
{
var next= new Array();
next= current.id.split('_');
var num = next[1] * 1 ; //get string to int
num++; //provides me with 2
document.getElementById('field_' + num).click(); //DO CLICK on
field_2 does not work

}


thanks in advance for any help...

 
Reply With Quote
 
 
 
 
web.dev
Guest
Posts: n/a
 
      08-11-2006

wrote:
> <div id='field_1' onclick='divclick(this, *(field1 specific data*))'
> ...> ...</div>
> <div id='field_2' onclick='divclick(this, *(field1 specific data*))'
> ...> ...</div>
>
> <input id="doclick" type="button" value="value" onclick='nextMove()'/>
>
> now, either field 1 or 2 is 'active' so i keep that stored in
> javascript as
>
> var current; //lets say it is pointing to 'field_1'
>
> function nextMove()
> {
> var next= new Array();
> next= current.id.split('_');
> var num = next[1] * 1 ; //get string to int
> num++; //provides me with 2
> document.getElementById('field_' + num).click(); //DO CLICK on
> field_2 does not work
>
> }


You must already have a function called divclick defined somewhere,
thus all you need to do is call your function in your nextMove
function. For example, if I were to go along with your divclick
parameters, I would use them in the following manner:

function nextMove()
{
var oCurrentField = document.getElementById("field_" + num);
//grab your field specific data
var fielddata = ...

divclick(oCurrentField, fielddata);
...
}

 
Reply With Quote
 
 
 
 
david sargent
Guest
Posts: n/a
 
      08-11-2006
Thanks for the quick response...maybe i am just missing something, but
the problem is the specific data is retrieved from a database, so it
would look like for example:

onclick='divclick(this, 13253, unique, moreunique)'

each one is unique and dynamically retrieved,
how do i pull '13253' out of the onclick without doing lots of nasty
parsing...is there an easy way to just pull these specific elements
out...

after i do: var oCurrentField = document.getElementById("field_" +
num);
alert(oCurrentField.onclick)

produces the string function(){divclick(this, ...)} but i dont want to
have to do nasty string functions if possible...and i dont want to just
add these variables into the string of html tags as that would not be
compliant....

so if there is an easy way to take an onclick event and pull the
attributes for it, how do i do it?

thanks




> You must already have a function called divclick defined somewhere,
> thus all you need to do is call your function in your nextMove
> function. For example, if I were to go along with your divclick
> parameters, I would use them in the following manner:
>
> function nextMove()
> {
> var oCurrentField = document.getElementById("field_" + num);
> //grab your field specific data
> var fielddata = ...
>
> divclick(oCurrentField, fielddata);
> ...
> }


 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      08-11-2006
david sargent wrote:
> Thanks for the quick response...maybe i am just missing
> something, but the problem is the specific data is
> retrieved from a database, so it would look like for
> example:
>
> onclick='divclick(this, 13253, unique, moreunique)'
>
> each one is unique and dynamically retrieved,
> how do i pull '13253' out of the onclick without doing
> lots of nasty parsing...is there an easy way to just
> pull these specific elements out...
>
> after i do: var oCurrentField = document.getElementById(
>"field_" + num);
> alert(oCurrentField.onclick)
>
> produces the string function(){divclick(this, ...)} but i
> dont want to have to do nasty string functions if
> possible...and i dont want to just add these variables
> into the string of html tags as that would not be compliant....


If - alert(oCurrentField.onclick) - gives you the string of the event
handling function - oCurrentField.onclick(); - would call that event
handler as a method of the DIV element (which is how it would normally
be called by the browser). The only issue that may exist when doing that
is the handling of event objects, but your event handler does not employ
the event so that is not relevant here.

> so if there is an easy way to take an onclick event and pull
> the attributes for it, how do i do it?

<snip>

There is no need, just call the function that already exists.

Richard.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Overriding an onclick with another onclick tomlong@gmail.com Javascript 4 01-26-2006 09:26 PM
button.onclick = new Function("func2()") + button.onclick foldface@yahoo.co.uk Javascript 2 09-26-2005 08:13 AM
Events Events Events Please Help Chris ASP .Net Web Controls 0 08-30-2005 08:21 PM
custom client-side onClick events for asp:button giant food ASP .Net 2 12-12-2003 08:19 PM
document.onclick=doIt() same as document.onclick=doIt ? bob Javascript 3 08-21-2003 12:14 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57