Note that there are some explanatory texts on larger screens.

plurals
  1. POSet the value of multiple form elements with the same ID, Paypal
    primarykey
    data
    text
    <p>I'm trying to figure out a paypal issue.</p> <p>I have multiple 'buy now' buttons on the page and I need to set a value for all of the buttons.</p> <p>The 'buy now' button elements all have the same ids. </p> <p>Each 'buy now' button represents a licence range, so there's '1-5', '6-10', '11-20, etc. I have a list of versions, they are dropped in the page as follows in a loop:</p> <pre><code>$strWeights1 .= "&lt;span id='1".$row['Tag']."' onclick='select_weight(this.id)' class='linkoff'&gt;". $row['Tag'] . "&lt;/span&gt; | "; </code></pre> <p>I might be over thinking this, but what would be the best way to set the selected 'version' in all the 'buy now' buttons?</p> <p>I am thinking of using the paypal variable 'item_number'</p> <p>Cheers</p> <p>Like I've said the buttons are from PayPal, I can't control the naming of there fields, hence the problem I'm up against.</p> <p>OK, so the select weight function just makes the span work like a href tags, turning on and off the 'buttons'.</p> <pre><code>function select_weight(value){ value = value.substr(1); document.forms["fontweight"]["fw"].value = value; //this.forms["item_number"].value = value; thin = document.getElementById('1Thin'); if(thin != null){ thin.className = "linkoff"; thin = document.getElementById('2Thin'); thin.className = "linkoff"; } light = document.getElementById('1Light'); if(light != null){ light.className = "linkoff"; light = document.getElementById('2Light'); light.className = "linkoff"; } book = document.getElementById('1Book'); if(book != null){ book.className = "linkoff"; book = document.getElementById('2Book'); book.className = "linkoff"; } medium = document.getElementById('1Medium'); if(medium != null){ medium.className = "linkoff"; medium = document.getElementById('2Medium'); medium.className = "linkoff"; } bold = document.getElementById('1Bold'); if(bold != null){ bold.className = "linkoff"; bold = document.getElementById('2Bold'); bold.className = "linkoff"; } heavy = document.getElementById('1Heavy'); if(heavy != null){ heavy.className = "linkoff"; heavy = document.getElementById('2Heavy'); heavy.className = "linkoff"; } black = document.getElementById('1Black'); if(black != null){ black.className = "linkoff"; black = document.getElementById('1Black'); black.className = "linkoff"; } //alert(value); fontweight1 = document.getElementById('1'+value); fontweight2 = document.getElementById('2'+value); fontweight1.className = "linkon"; fontweight2.className = "linkon";} </code></pre> <p>This is the code for the buttons, it is in the page about 16 times, the 'item_name' and 'hosted_button_id' change each time:</p> <pre><code>&lt;form target=\"paypal\" action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\" onsubmit=\"return validateForm()\" &gt; &lt;input type=\"hidden\" name=\"cmd\" value=\"_s-xclick\"&gt; &lt;input type=\"hidden\" name=\"hosted_button_id\" value=\"xxxxxxxx\"&gt; &lt;input type=\"hidden\" name=\"item_name\" value=\"".$strProdName." : 1-5 terminals \"&gt; &lt;input type=\"hidden\" name=\"item_number\" value=\" [set this value] \"&gt; &lt;input type=\"image\" onMouseOver=\"this.src='images/paypalon.png';\" onMouseOut=\"this.src='images/paypaloff.png';\" src=\"images/paypaloff.png\" border=\"0\" name=\"submit\" alt=\"PayPal — The safer, easier way to pay online.\"&gt; &lt;input type='hidden' name='notify_url' value='http://ipn.php'&gt; &lt;/form&gt; </code></pre> <p>I've been thinking about how to sort this out. Can I use the form validation function to access the specific form and set the value that way? I have been trying this with any success.</p> <pre><code>function validateForm(form) { var x=document.forms["fontweight"]["fw"].value; if (x==null || x=="") { alert("Hold on a moment, you need to select a weight before hitting the ‘Buy’ button."); return false; } else{ field = document.form; //this.form['item_number'].value = x; alert(field['item_name'].value); return false; } } </code></pre> <p>the form tag has this call in it</p> <pre><code>onsubmit="return validateForm(this.form)" </code></pre> <p>Am I on the right track> or should I ditch it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload