Eraatic Help please

The code works the first time around, the second time around only the checkboxes get clicked but no prompts



<label><input type="checkbox" name="install"  <?php  if(isset($_GET['install'])) { echo 'checked'; } ?>
id='install'  value="Install"   onchange="this.form.submit()"> Install & Comm</label>
<label><input type='checkbox' name='freight'  <?php  if(isset($_GET['install'])) { echo 'checked'; } ?>
id='freight'  value='freight'  onchange='this.form.submit()'> Freight Charges</label> 
<label><input type='checkbox' name='discount'  <?php  if(isset($_GET['install'])) { echo 'checked'; } ?>
id='discount'  value='discount'  onchange='this.form.submit()'> Discount</label>       
<script>
    function getValueInstall() {
var installAmount = prompt("Enter Install Value");
      if (installAmount>0) {
      window.location.href = (window.location.href.split('?')[0]) + "? install=on + p1=install &installp2=" + installAmount;
      } else {
            window.location.href = (window.location.href.split('?')[0]) + "? p1=install& p2=" + installAmount;     
      }
}
document.getElementById("install").onclick = getValueInstall;
    function getValueFreight() {
var freightAmount = prompt("Enter Freight Value");
      if (freightAmount>0) {
      window.location.href = (window.location.href.split('?')[0]) + "? freight=on + p1=freight &freightp2=" + freightAmount;
      } else {
            window.location.href = (window.location.href.split('?')[0]) + "? p1= & p2=" ;     
      }
}
document.getElementById("freight").onclick = getValueFreight;
    function getValueDiscount() {
var discountAmount = prompt("Enter Discount Value");
      if (discountAmount>0) {
      window.location.href = (window.location.href.split('?')[0]) + "? discount=on + p1=discount & discountp2=" + discountAmount;
      } else {
            window.location.href = (window.location.href.split('?')[0]) + "? p1= & p2=" ;     
      }
}
document.getElementById("discount").onclick = getValueDiscount;
</script>

You need to use your browser’s developer tools/console tab and also view the source of the page in your browser to investigate what is occurring. You are getting an error about trying to set the onclick property on a null value. This is because there’s no space between the ‘checked’ keyword and the id=’…’. attribute. You end up with checkedid=’…’, so, when the javascript tries to use getElementById("…"), there are no id attributes at all in the markup.

In addition to that issue, there are some typographic mistakes in the code. The php isset() tests are all using the same element and all the extra spaces and + characters, inside the strings in the javscript are incorrect and are not producing the expected/valid URLs (take a look at your browser’s address bar.)

thanks will check it out

Sponsor our Newsletter | Privacy Policy | Terms of Service