<?php
echo '

<script type="text/javascript">

var ri = new obj($src);
ri.write();

</script>

<NOSCRIPT><INPUT TYPE=RESET></NOSCRIPT> ';

?>

$src is php variable. I have already tried the following. But it also doesnt work

var ri = new obj(<?php echo $src; ?>);

And again this too...

echo " var ri = new obj($src);";

    here is another variation.

    var ri = new obj("<?=$src?>");

    $src is passed to javascript function now. But only text is shown instead of image.

    Can anybody give me a hint ?? Thanks in advance.

      Dear all,

      I would like to pass php variable to javascript function. I have already read the 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 .... when php variable is passed like this, image button is not shown. Instead of it, text 'Reset' is shown. But this text actually reset other fields. I mean 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 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>

        Write a Reply...