Javasscript coding help needed...

6 posts by 2 authors in: Forums > CMS Builder
Last Post: October 14, 2013   (RSS)

Hi Jerry,

Is this code being added to the page via a script tag? If it is you could use the same PHP code that is stopping the fields from being displayed to remove the error checking from the script tag.

What code is being used to decide if the os2 and os1 fields are being displayed?

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gkornbluth - August 6, 2013 - edited: August 6, 2013

Hi Greg,

Thanks for looking at this.

There are two different scenarios. Both in the form code.

For the colors, the existence of a checked color choice on the item record <?php if($store_inventoryRecord['colors'] ):?>

And for the Programs: a checkbox in a single record editor used as a global value

<?php if($common_informationRecord['list_sources'] == '1' ):?>

Hope that helps to help me

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Hi Jerry, 

What about doing something like this:

<script type="text/javascript" language="JavaScript">
  function PackageForm(frm) {
    var emsg = '';

    //Review all your form fields that you want to require.
    //add your error message to the "emsg" variable.
    // variable must be unique


    <?php if($store_inventoryRecord['colors'] ):?>
      var i = frm.os1.selectedIndex;
      if (i == 0) {
        emsg += "Please select a color\n";    
      }
     <?php endif; ?>


    <?php if($common_informationRecord['list_sources'] == '1' ):?>
      var i2 = frm.os2.selectedIndex;
        if (i2 == 0) {
        emsg += "Please tell us where you heard about us.\n";
      }
     <?php endif; ?>

    //if emsg is empty, the Order is OK, so proceed to PayPal.
    //if emsg is NOT empty, show error message(s).
    if (emsg == '') {
      return true;
    }else {
      alert(emsg);
      return false;
    }
  }
</script>

This is just example code, so you might have to make a few changes to get it working.

So depending on if the OS2 or OS1 fields are displayed, decides if the validation functionality for the JS code is included on the page. If niether of the fields are displayed, then the code emsg will equal nothing.

Cheers!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Thank you sir,

You make it look so simple.

That's probably one of the only variation that I didn't explore...

I'll give it a try.

Thanks,

Jerry

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Hi Greg,

Sorry to come back with this at the last minute, but when my client started adding records to the current_marketing_programs editor, I realized that there was an undefined index $value error on my page and the form seems to not work correctly. (The last value in the list appears in the drop down box instead of, ‘Where did you hear about us’) And the form submits as if that value was selected.

If I select ‘Where did you hear from us’, the correct popup appears saying “Please tell us where you heard about us”.

I’ve been playing with this for a while and need some more expert guidance, there’s a client review tomorrow and they’d like to have it working.

The URL is http://www.rcartierperry.com/store.php and the first group “Victory” is the one I’ve been testing.

Thanks,

I've sent login info to your email just in case

Jerry Kornbluth

   Here's the active part of the form

                          <?php if($common_informationRecord['list_marketing_programs'] == '1' && $current_marketing_programsRecords):?>
                          <input type="hidden" name="on2" value="Source">
                          <select name="os2">
                          <?PHP $value ="" // added because $value came back as undefined?>
                           <option value="">Where Did You Hear About Us?</option>
                            <?php foreach ($current_marketing_programsRecords as $record): ?>
                            <option value = " <?php echo ($record['title']) ?>" <?php selectedIf($value, @$_REQUEST['source']);?>> <?php echo ($record['title']); ?></option>
                            <?php endforeach; ?>
                          </select>
                          <?php endif?>

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php