PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 22nd, 2005, 10:33 PM
mitchell_1078 mitchell_1078 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 mitchell_1078 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 2 sec
Reputation Power: 0
how to pass image src (php variable )to javascript

Dear all,

I would like to pass php variable to javascript function. I have already read the previous messages about it. But it doesnt still work.

<?php
session start();
....
$src = $language_config_key_value_pairs['reset']; // it means => $src = "btn-reset.gif"
echo '
<script type="text/javascript">
var ri = new resetimage("<?=$src?>"); // if I try var ri = new resetimage("btn-reset.gif"), image button is shown.
ri.write();
</script>
<NOSCRIPT><INPUT TYPE=RESET></NOSCRIPT> ';
.......
?>

The problem is passing php variable like this, image button is not shown. Instead of it, text 'Reset' is shown. But this text actually reset other fields. It also works. But I can't see image button. Can anybody help me ?

Here is my javascript function : Functionally speaking, this function makes image reset button reset other text fields. I have already tested this function. It works properly.


<SCRIPT TYPE="text/javascript">

var resetRolls = new Object();
function resetimage(src)
{
this.src=src;
this.confirm=true;
this.alt="Reset";
this.write=resetimage_write;
}
function resetimage_write()
{
document.write(\'<A \');
if (this.rollover)
{
if (! this.name)
{
alert(\'to create a rollover you must give the image a name\');
return;
}
resetRolls[this.name] = new Object();
resetRolls[this.name].over = new Image();
resetRolls[this.name].over.src=this.rollover;
resetRolls[this.name].out = new Image();
resetRolls[this.name].out.src=this.src;
document.write(
\' onMouseOver="if (document.images)document.images[\\\'\' +
this.name + \'\\\'].src=resetRolls[\\\'\' + this.name + \'\\\'].over.src"\' +
\' onMouseOut="if (document.images)document.images[\\\'\' +
this.name + \'\\\'].src=resetRolls[\\\'\' + this.name + \'\\\'].out.src"\'
);
}
document.write(\' HREF="javascript:\');
document.write(
\'document.forms[\' +
(document.forms.length - 1) + \'].reset();void(0);">\');
document.write(\'<IMG SRC="\' + this.src + \'" ALT="\' + this.alt + \'"\');
document.write(\' BORDER=0\');
if (this.name)document.write(\' NAME="\' + this.name + \'"\');
if (this.height)document.write(\' HEIGHT=\' + this.height);
if (this.width)document.write(\' WIDTH=\' + this.width);
if (this.otheratts)document.write(\' \'+ this.otheratts);
document.write(\'></A>\');
}
</SCRIPT>

var resetRolls = new Object();
function resetimage(src)
{
this.src=src;
this.confirm=true;
this.alt="Reset";
this.write=resetimage_write;
}
function resetimage_write()
{
document.write(\'<A \');
if (this.rollover)
{
if (! this.name)
{
alert(\'to create a rollover you must give the image a name\');
return;
}
resetRolls[this.name] = new Object();
resetRolls[this.name].over = new Image();
resetRolls[this.name].over.src=this.rollover;
resetRolls[this.name].out = new Image();
resetRolls[this.name].out.src=this.src;
document.write(
\' onMouseOver="if (document.images)document.images[\\\'\' +
this.name + \'\\\'].src=resetRolls[\\\'\' + this.name + \'\\\'].over.src"\' +
\' onMouseOut="if (document.images)document.images[\\\'\' +
this.name + \'\\\'].src=resetRolls[\\\'\' + this.name + \'\\\'].out.src"\'
);
}
document.write(\' HREF="javascript:\');
document.write(
\'document.forms[\' +
(document.forms.length - 1) + \'].reset();void(0);">\');
document.write(\'<IMG SRC="\' + this.src + \'" ALT="\' + this.alt + \'"\');
document.write(\' BORDER=0\');
if (this.name)document.write(\' NAME="\' + this.name + \'"\');
if (this.height)document.write(\' HEIGHT=\' + this.height);
if (this.width)document.write(\' WIDTH=\' + this.width);
if (this.otheratts)document.write(\' \'+ this.otheratts);
document.write(\'></A>\');
}
</SCRIPT>

Reply With Quote
  #2  
Old February 23rd, 2005, 03:30 AM
mitchell_1078 mitchell_1078 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 mitchell_1078 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 2 sec
Reputation Power: 0
I got it. Thanks!

Reply With Quote
  #3  
Old February 23rd, 2005, 08:57 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
I realize you solve the problem, but i'll state what I think the solution would look like
If you did it a different way, feel free to post that.
Hopefully this thread will help others as well.

PHP Code:
 $src $language_config_key_value_pairs['reset']; // it means => $src = "btn-reset.gif"
echo '
<script type="text/javascript">
[b]var ri = new resetimage("'
.$src.'");[/b] // if I try var ri = new resetimage("btn-reset.gif"), image button is shown.
ri.write();
</script>
<NOSCRIPT><INPUT TYPE=RESET></NOSCRIPT> '


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > how to pass image src (php variable )to javascript


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT