I am working on an ecommerce checkout form. On the Shipping/Billing page, I have a "Same as billing" checkbox.
What I'd like to do is if the checkbox is not set, change the form so all of the shipping fields are required and have the red asterix, validate, etc.
This is what I have so far
1) My form element in a form function:
$form['address']['shippingSame'] = array('#id' => 'sameship-box', '#attributes' => array('onclick' => 'mod_class_fields(this.value);'), '#type' => 'checkbox', '#title' => t('Same as billing address.'), '#weight'=>-40);
2) The Javascript (borrowed from here http://www.ubercart.org/drupal_module_and_jquery_guides/code_explanation)
I am not strong in javascript at all - how should I be communicating with FAPI through jQuery?
<?php
drupal_add_js('$(document).ready(function(){
// Ready code here.
if ($("#class-box").val() > 0)
mod_class_fields($("#sameship-box").val());
} );
//mod fields
function mod_class_fields(class_id) {
if (class_id == 1) {
//$("#billing-fields").hide("slow").empty();
$form['address']['shipping']['firstname']['#required'] = TRUE;
$form['address']['shipping']['lastname']['#required'] = TRUE;
//etc
} else {
$form['address']['shipping']['firstname']['#required'] = FALSE;
$form['address']['shipping']['lastname']['#required'] = FALSE;
//etc