?
Solved

add javascript

Posted on 2003-10-28
7
Medium Priority
?
213 Views
Last Modified: 2011-09-20
perl/CGI code :
    print p(checkbox("fries",0,"yes","Fries")) ;

html code:
    <input name="checkbox" type="checkbox" onMouseOver="showPic(1)" value="checkbox">

is there a way to add the onMouseOver to the perl code?? thank you!!
0
Comment
Question by:ocsurf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 20

Expert Comment

by:jmcg
ID: 9639373
You'll need to use the named parameter methods of CGI to get this to work properly:

print p(checkbox( -name=>"fries", -checked=>0, -value=>"yes",
           -label=>"Fries", -onMouseOver=>"showPic(1)"));

The attribute name will be lower-cased, but that does no harm to the functionality:

<p><input type="checkbox" name="fries" value="yes" onmouseover="showPic(1)" />Fries</p>
0
 
LVL 1

Author Comment

by:ocsurf
ID: 9642491
is it better or makes a difference it you preform the html functions This way
#Perl
    print start_form() ;
    # add both textfields to form
    print p("Name: ", textfield("name")) ;
    print p("E-mail address: ", textfield("site")) ;
    # add the dogs we initialized in dogs array
    print p(radio_group("dog", \@dogs,"Big dog",1)) ;

or------------
#printing html
print qq(<form name="form1" method="post" action="">
<table width="735" border="1" summary="main">
  <caption>
  main table
  </caption>
  <tr>
    <td width="159" height="247">
<input name="checkbox" type="checkbox" onMouseOver="showPic(1)" value="checkbox">
Plain Dog <p><input name="checkbox" type="checkbox" onMouseOver="showPic(3)" value="checkbox"> Cheese Dog </p></td>.......etc
0
 
LVL 1

Author Comment

by:ocsurf
ID: 9642651
Forget the last question i figured it out. But how would i do this

@dogs = ('Big dog','Cheese Dog','Plain dog') ;
print p(radio_group("dog", \@dogs,"Big dog",1)) ;

for big dog i would like the mouse over to call showpic(3)
for Cheese dog i would like the mouse over to call showpic(4)
for Plain dog i would like the mouse over to call showpic(5)

is there way, it tried to to do it like above but i think it is because it is an array and a radio group? right?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:ocsurf
ID: 9642658
add 100 points
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9643945
From CGI pod:


              print $query->radio_group(-name=>'group_name',
                                        -values=>['eenie','meenie','minie'],
                                        -default=>'meenie',
                                        -linebreak=>'true',
                      -labels=>\%labels,
                      -attributes=>\%attributes);

                   -or-

              print $query->radio_group('group_name',['eenie','meenie','minie'],
                       'meenie','true',\%labels,\%attributes);

==========

So, if you wish to continue to avoid the keyword-based parameters, you could do:

@dogs = ('Big dog','Cheese Dog','Plain dog') ;
@dogattr{ @dogs } = ( { onmouseover=>{ 'Big dog'=>"showpic(3)" },
               { onmouseover=>"showpic(4)" },
               { onmouseover=>"showpic(5)"} );

print p(radio_group("dog", \@dogs, 'big dog', 1, { }, \%dogattr));

It turns out we have to use the un-minused attribute names in the %dogattr array because of the way the set_attributes routine works internal to CGI.pm.

Anyway, the above code gives me:

<p>
<input type="radio" name="dog" value="Big dog" onmouseover="showpic(3)" />
Big dog<br />
<input type="radio" name="dog" value="Cheese Dog" onmouseover="showpic(4)" />
Cheese Dog<br />
<input type="radio" name="dog" value="Plain dog" onmouseover="showpic(5)" />
Plain dog<br />
</p>

except I inerted some newlines to add clarity and keep the lines from getting too long.
0
 
LVL 1

Author Comment

by:ocsurf
ID: 9644910
@dogattr{ @dogs } = ( { onmouseover=>{ 'Big dog'=>"showpic(3)" },
               { onmouseover=>"showpic(4)" },
               { onmouseover=>"showpic(5)"} );

this part the {} don't match up, there may be an extra on? I'm learning all this, why did you put a %             but at the top you put a @

   |                                                  |
   V                                                 V
 \%dogattr));                                  @dogattr

thank you for the help
0
 
LVL 20

Accepted Solution

by:
jmcg earned 1000 total points
ID: 9645872
Aw, shucks. I posted one of the experimental expressions rather than the one that worked!


@dogs = ('Big dog','Cheese Dog','Plain dog') ;
@dogattr{ @dogs } = ( { onmouseover=>"showpic(3)" },
               { onmouseover=>"showpic(4)" },
               { onmouseover=>"showpic(5)"} );

print p(radio_group("dog", \@dogs, 'big dog', 1, { }, \%dogattr));

You see, I was having trouble getting this to work and it ultimately required going to the source code of the CGI.pm module to figure out what was going wrong.

The @dogadattr{ @dogs } expression is a _slice_ assignment. I'm assigning the list on the right (which contains a sequence of anonymous hash references) to the list on the left, which consists of the members of the %dogattr hash referred to (indexed) by the array @dogs.


0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question