in reply to CGI delete attributes set in textfield()

You've got a static argument list, so there's no way to "delete" them short of editing the code. So instead of hard-coding it what you need to do: build up the argument list in a variable, adding in the onfoo attributes if needed, then pass that dynamic list to the textfield method.

my @textfield_args = ( -name => 'name', ..., -maxlength => 120, ); if( $was_no_change ) { push @textfield_args, -onfocus => 'this.value = ''"; push @textfield_args, -onblur => 'this.value = 'def'"; push @textfield_args, -onchange => 'delete onfocus, delete onblur"; } $string .= $cgi->textfield( @textfield_args );

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: CGI delete attributes set in textfield()
by KaiAllard_ (Initiate) on Feb 21, 2008 at 15:21 UTC
    Thank you Fletch, but I know of a change through the -onchange method of javascript available in CGI so it is not quite that what you coded for me. It would be much easier (IMHO) if there would be a possibility that do the following
    -onchange => "override onfocus, override onblur",
    Nevertheless thank you for your help.

      Aaah I misunderstood what you were asking, which is a Javascript question and not really a Perl problem (whatever JS library you're using should provide some method of removing or changing event bindings; e.g. jquery would be something like $("textfield[name=name]").unbind( 'focus' ); $("textfield[name=name]").unbind('blur');).

      Update: tweaks to sample jquery and link'd to unbind docs

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.