Jump to content


This topic is now archived and is closed to further replies.


Integrating JS within a PHP page

Recommended Posts

I've written a php page to display items from a DB, which works fine. But in one instance, in addition to the DB info I wish to display dropdown boxes that impart additional info to be processed by a JS before the add to cart button is clicked. The JS doesn't seem to be working and I'm pretty certain it is JS & PHP interaction issue. When the JS is in an HTML page, it works perfectly. Any ideas of what I need to do to get these to work together?

Here is a short version of the code:[code]
// In the head: <script type="text/javascript">the javascript that executes with onchange, onclick and onsubmits below</script>

//Now for the php & JS issues
if ($mono == "Y") {

echo"<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\"
onsubmit=\"this.target = 'paypal'; return ReadForm(this, true);\">

    <input type=\"hidden\" name=\"cmd\" value=\"_cart\">
    <input type=\"hidden\" name=\"add\" value=\"1\">
    <input type=\"hidden\" name=\"business\" value=\"$PPEMAIL\">
    <input type=\"hidden\" name=\"item_name\" value=\"\">
    <input type=\"hidden\" name=\"amount\" value=\"\">
    <input type=\"hidden\" name=\"currency_code\" value=\"USD\">
    <input type=\"hidden\" name=\"baseamt\" value=\"$P\" >
    <input type=\"hidden\" name=\"basedes\" value=\"$T\">
    <input type=\"hidden\" name=\"baseon0\" value=\"Color\">
    <input type=\"hidden\" name=\"baseos0\" value=\"\">
    <input type=\"hidden\" name=\"baseon1\" value=\"Size\">
    <input type=\"hidden\" name=\"baseos1\" value=\"\" >
    <input type=\"hidden\" name=\"baseitn\" value=\"\" >
    <input type=\"hidden\" name=\"on0\" value=\"\" >
    <input type=\"hidden\" name=\"os0\" value=\"\" >
    <input type=\"hidden\" name=\"on1\" value=\"\" >
    <input type=\"hidden\" name=\"os1\" value=\"\" >
    <input type=\"hidden\" name=\"item_number\" value=\"$I\" >
      <td rowspan=2 width=\"20%\" valign=\"top\">
        <div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=2><a href=\"$SCIMAGEPATHLISTINGSR/$PU\"><img src=\"$SCIMAGEPATHLISTINGSR/$PU\" width=200
height=150 border=\"0\"></a></font></div>
      <td width=\"57%\" valign=\"top\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\" color=\"#000033\"><b>$T</b></font> <br><b>Item #: $I</b> <br><b><font color=\"#FF0000\">$P</font></b>
      <td width=\"23%\" valign=\"top\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">Quantity
        <input type=\"text\" name=\"quantity\" size=\"3\" value=1 ><br>Total price </font>
        <input class=\"nbor\" type=\"text\" name=\"tot\" size=8 value=\"$P\" />
      <td width=\"57%\">
        <p><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">$D </font></p>
        <p><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">Color -
        <select name=\"color_1b\">
            <option value=\"White\">White</option>
            <option value=\"Red\">Red</option>
            <option value=\"Blue\">Blue</option>
          &nbsp;&nbsp;&nbsp; Size -
          <select onChange = \"ReadForm (this.form, false);\" name=\"size_2b\">
            <option value=\"S\">Small</option>
            <option value=\"M +0.50\">Medium (+0.50)</option>
            <option value=\"L +1.00\">Large (+1.00)</option>
        <p><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">Embroidered
          Monogram? &nbsp;
          <input type    = \"radio\"  value  = \"Monogram +0.50\"  name  = \"monogram\"
      onClick  = \"ReadForm (this.form, false);\">Yes<br >
          Monogram Text: &nbsp;&nbsp;
          <input type=\"text\" name=\"mono-text\" size=\"20\" ><br >
          Monogram Font:&nbsp;&nbsp;&nbsp;
          <select name=\"mono-font\">
            <option value=\"\" selected>Select Font</option>
            <option value=\"arial\">Arial</option>
            <option value=\"verdana\">Verdana</option>
          Embroidery Color:&nbsp; </font>
          <select name=\"select\">
            <option value=\"\" selected>Select Color</option>
            <option value=\"E-blue\">blue</option>
            <option value=\"E-red\">red</option>
      <td width=\"23%\">
        <input type=\"image\" src=\"https://www.paypal.com/en_US/i/btn/x-click-but22.gif\" name=\"submit\" alt=\"cart add\" > <br>
        <input type    = \"button\"
      value  = \"Reset\" name=\"button\"
      onClick = \"this.form.reset();\"  name=\"button\" >

I have already tried one approach that converts the JS events in the PHP to PHP variables & concatenates them so PHP inserts the JS code, but that didn't work. Any help would be greatly appreciated!

Share this post

Link to post
Share on other sites

Thank you fo the reply. I'm sorry I didn't see your response earlier(been sick), and have deconstructed that page, going to use PHP only. The problem seemed to come from JS trying to modify some php variables ($P and $T.) Thank you again for trying!!

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.