[Phpwm] [OT]event trigger

Paul Matthews paul.matthews.86 at gmail.com
Wed Mar 14 21:16:38 GMT 2007


On 3/14/07, David Goodwin <david at codepoets.co.uk> wrote:
>
> Phil Beynon wrote :
> > > > Does anyone know how to get a javascript on-event trigger to fire
> from a
> > > > right click menu paste into a form input field?
> > > > I'd have thought that a set focus on window load might have done it,
> but
> > > > it
> > > > didnt!
> > > > It works fine on typing into the field and ctrl V.
> > > >
> > > > I Googled it for a bit but didn't see anything conclusive.
> > > >
> > > >
> > > > Regards,
> > > >
> > > > Phil Beynon
> > >
> > > I'm not sure I know exactly what you're asking, although this might
> help.
> > >
> > > I don't believe you can specify an event as details as to which item
> they
> > > press in after using the right mouse button.
> > > Perhaps this solves some of your problem though:
> > > http://www.w3schools.com/js/tryit.asp?filename=try_dom_event_button is
> an
> > > example to work out which mouse button was pressed. Then whatever
> you'd do
> > > after that would be much the same as before.
> > >
> > > >From Paul.
> >
> > I am so stupid sometimes......
> >
> > I have two pretty much identical forms on the page concerned, one for
> adding
> > a record, the other for editing - I was adding on-events to one and
> testing
> > the effect on the other form!
> >
> > This works now;
> >
> > <input name="group_name" class="MedInput" type="text" value="<?php echo
> > $myrow["group_name"]; ?>" size="50" maxlength="50"
> > onfocus="textCounter(this,'progressbar2',50);FldVal(document.formthree
> );"
> > onKeyDown="textCounter(this,'progressbar2',50)"
> > onKeyUp="textCounter(this,'progressbar2',50);FldVal(document.formthree
> );"
> > onMouseDown="textCounter(this,'progressbar2',50);FldVal(
> document.formthree);
> > "
> > onMouseOver="textCounter(this,'progressbar2',50);FldVal(
> document.formthree);
> > "
> > onMouseOut="textCounter(this,'progressbar2',50);FldVal(
> document.formthree);"
> > >
> > <div id="progressbar2" class="progress"></div>
> > <script>textCounter(document.getElementById
> ("group_name"),"progressbar2",50)
> > </script>
> >
> > Which if anyone wants the source is a routine that does a text counter
> > bargraph / submit disable until required field(s) populated / disable
> after
> > submit.
> >
>
> By which I presume you mean you get a bar that says, e.g. the form is
> 90% complete?
>
> I don't know much about Javascript, but I seem to keep hearing from
> others that it's best to not include Javascript inline with HTML, and
> instead 'attach' listeners (or whatever they're called) by loading
> relevant JS files in the <head> </head>..... Paul can/might/could say
> more about such things.
>
> David.
>
> --
> David Goodwin
>
> [ david at codepoets dot co dot uk ]
> [ http://www.codepoets.co.uk       ]
>
> _______________________________________________
> Phpwm mailing list
> Phpwm at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/phpwm


Yeah as david said, really nowerdays we're (as in web developers as a whole)
are (or should be) trying to keep javascript out of html pages. What you
then do is install the hooks using the javascript. As a rule of thumb this
is done in "window.onload".


An example might be:

### init.js ###
window.onload = init();

function init() {
    document.getElementById('foo').onmouseove = barr();
    // etc.
}


function foo() {
    // function body...
}

### end ###

### index.php ###
<html>
    <head>
        <script type='javascript' src='init.js'></script>
    </head>
    <body>
        <!-- Page Content -->
    </body>
</html>

### end ###

Although if you were to do it properly I believe you should try
addEventListner() or something first. But that's just good practise.

Hope this helps,
from Paul


More information about the Phpwm mailing list