Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

Using onClick and JS

Javascript coding ..

Moderators: macek, egami, gesf

Using onClick and JS

Postby popeye » Tue Feb 22, 2005 6:51 am

I have a series of small thumbnails on a page. Every time there is a mouse click on any of them I need to show the original image in a certain fixed location on top of an existing image (Pow.jpg) on the same page. I have the code like the following and tried to modify an existing MouseOver JS for onClick like below:
Code: Select all
=========================
 <script language='javascript'>
    function ImgClicked(FormName,MouseFunction,Org_Image,Alt_Image,Max_x,Max_y) {
    i_MouseClicked = new Image(Max_x,Max_y);
    i_MouseClicked.src = Alt_Image;
    document.images[FormName].src = eval(MouseFunction + '.src');  }
   </script>
=========================
<INPUT type='hidden' name='i_PoWForm' value=''>
<img src='pow.jpg' alt='PoW picture' align='right' border='1' name='i_PoWForm'>
<input type='image' src='$i_ThumbNail' alt='$i_ImageFile' border='1' onClick="ImgClicked('i_PoWForm','onClick','pow.jpg','$i_ImageFile','485','420'); this.form.submit();">
=========================


Some times I get "error on page" when the thumbnail is clicked, some times I get nothing. I am sort of lost and I have exhausted all possible sources of help on the web. Can you help or maybe you can direct me where to look to find info for my onClick problem? Thanks
User avatar
popeye
New php-forum User
New php-forum User
 
Posts: 120
Joined: Sat Jan 03, 2004 7:06 pm
Location: New York, NY

Postby Alexej Kubarev » Tue Feb 22, 2005 8:13 am

what are $_thumb and so on? PHP variables? in that case you should use <?= ?> around them

Please explain better your code
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby popeye » Tue Feb 22, 2005 11:40 am

Yes. They are PHP vaiables and they have <? ?> around them in the original code. I just discard them here for simplecity!!!! :sad:
User avatar
popeye
New php-forum User
New php-forum User
 
Posts: 120
Joined: Sat Jan 03, 2004 7:06 pm
Location: New York, NY

Postby swirlee » Tue Feb 22, 2005 1:47 pm

Actually <?= ?> is different from <? ?>. The = denotes an echo. It's a shorthand that you really shouldn't use, because if you switch to a host that requires full PHP tags (i.e. <?php ?>), the shorthand won't work.

Anyway, what you need to do is make sure you're echoing (i.e. printing) the value. Just putting the name of the variable in a section of HTML doesn't make the variable evaluated. You have to actually echo it. You could use the shorthand above, but like I said, it's a bad idea. Something like this is what you need. Rather, put <?php echo $i_ThumbNail; ?>, for example:

Code: Select all
<INPUT type='hidden' name='i_PoWForm' value=''>
<img src='pow.jpg' alt='PoW picture' align='right' border='1' name='i_PoWForm'>
<input type='image' src='<?php echo $i_ThumbNail; ?>' alt='<?php echo $i_ImageFile; ?>' border='1' onClick="ImgClicked('i_PoWForm','onClick','pow.jpg','<?php echo $i_ImageFile; ?>','485','420'); this.form.submit();">
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby popeye » Wed Feb 23, 2005 6:10 am

Thanks for your concern but I have taken care of the PHP part. My issues here are the JS for onClick function and changing the images. :shock:
User avatar
popeye
New php-forum User
New php-forum User
 
Posts: 120
Joined: Sat Jan 03, 2004 7:06 pm
Location: New York, NY

Postby swirlee » Wed Feb 23, 2005 7:54 am

You'd have to tell us what error you're getting. Try using a JavaScript debugger, like Firefox's JavaScript console or Venkman.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back


Return to JavaScript

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron