Jump to content

Trying to disable submit until a select option has been chosen


richrock

Recommended Posts

I'm tearing hair out at a rate of knots, as I'm completely new to JS, so here goes:

 

I have a page with two independent forms, each of which has 1 select list and 1 submit button.

 

I've tried to hunt for a solution, and thought 'what the heck' and tried to do it myself  :o

 

Anyhoo, here's what I came up with - you may laugh if you want :

 

Head JS Code :

 <script type="text/javascript">
  function activateGo(id) {

        var o = document.evangelistselect.id.value; // or any other ref. like your array

        // Determines the output and sets teh submit button to active or disabled.
        if (o == "Select Evangelist") {
            var link_go = false;
        } else {
            var link_go = true;
        }

        //alert(link_go);
        alert(go1);
        if (go1.disabled) {
            go1.disabled = false;
        } else go1.disabled = true;
        
  }

  </script>

Form Elements (from PHP)

 <td valign="top" id="pagenav-block">
  <?php
    // This select chooses the evangelist from a drop-down choice.
    $getContent = "SELECT * FROM jos_content WHERE sectionid = '6' AND catid = '36' AND state = '1' ORDER BY ordering ASC";
    $resContent = mysql_query($getContent);
    ?><table border="0" cellpadding="0" cellspacing="0" align="left">
      <tr>
        <td style="padding-right:6px;" valign="top" height="23">
          <form action="index.php" method="get" name="evangelistselect">
          <input type='hidden' name='option' value='com_content' />
          <input type='hidden' name='view' value='article' />
          <input type='hidden' name='catid' value='36' />
          <input type='hidden' name='Itemid' value='56' />
          <select name="id" onchange="activateGo()">
                <option name="id" value="Select Evangelist">Select Evangelist</option>
                <?php
                  while ($rowContent = mysql_fetch_array($resContent)) {

                  $PRO_title = $rowContent['title'];
                  $PRO_itemid = $rowContent['id'];
                  $PRO_alias = $rowContent['title_alias'];
                  $PRO_authid = $rowContent['created_by'];

                  echo "<option name='id' value='".$PRO_itemid.":".$PRO_title_alias."&authid=".$PRO_authid."'>";
                  echo $PRO_title;
                  echo "</option>";
                  }
                  ?>
            </select>
            </td><td style="padding-right:12px;" height="23">
            <button name="go1" value="Go" id="link_go_a" disabled>Go</button>
          </form>
        </td>
        <td valign="top" style="padding-right:6px;" height="23">
        <form action="index.php" method="get" name="evanglocation">
          <input type="hidden" name="option" value="com_content" />
          <input type="hidden" name="view" value="article" />
          <input type="hidden" name="catid" value="36" />
          <input type="hidden" name="Itemid" value="56" />
          <select name="id">
              <option name="layout" value="userlist">Select Location</option>
                <?php
                  // Get the location keywords from the userprofiles
                  $getLocation = "SELECT  jos_users.id, jos_users.username, ";
                  $getLocation .= "jos_users.email, jos_users.params ";
                  $getLocation .= "FROM jos_users ";
                  $getLocation .= "JOIN jos_contact_details ";
                  $getLocation .= "ON jos_users.id = jos_contact_details.user_id ";
                  $getLocation .= "WHERE jos_contact_details.catid = '65' ";
                  $getLocation .= "AND jos_contact_details.published = '1' ";
                  $resLocation = mysql_query($getLocation);
                  $numLocations = mysql_numrows($resLocation);
                  //for($i = 0; $i < $numLocations; $i++) {
                    while ($rowUserInfo = mysql_fetch_array($resLocation)) {
                      $PRO_id = $rowUserInfo['id'];
                      $PRO_parameters = $rowUserInfo['params'];
                      $PRO_parameters = split("\n", $PRO_parameters);
                      $mainloc = $PRO_parameters[10];
                      $mainloc   = split("=", $mainloc);
                      $mainloc = $mainloc[1];

                      $mainlocations[] = $mainloc;
                      $mainid[] = $PRO_id;
                    } //endwhile

                    foreach ($mainlocations as $nook => $place) {
                      // get the value of the item for display
                      // Need to get the ID of who ever is in that particular location
                      $getLoc = "SELECT * FROM jos_users WHERE id = ".$mainid[$nook]."";
                      $resLoc = mysql_query($getLoc);

                      $getLV = "SELECT * FROM jos_users WHERE ";
                      $getLV .= "id = '".$mainid[$nook]."'";
                      $resLV = mysql_query($getLV);
                      $rowLV = mysql_fetch_array($resLV);
                      $LocValID = $rowLV['id'];
                      $Param = $rowLV['params'];
                      $Param = $Param[10];
                      $Param = split("=", $Param);
                      $Param = $Param[1];

                      //// Now we have the ID, let's get teh article
                      $getLVArt = "SELECT * FROM jos_content WHERE created_by = '".$mainid[$nook]."' AND sectionid = '6' AND catid = '36' and state = '1'";
                      $resLVArt = mysql_query($getLVArt);
                      $rowLVArt = mysql_fetch_array($resLVArt);
                      $LOC_title_alias = $rowLVArt['alias'];
                      $LOC_title = $rowLVArt['title'];
                      $LOC_itemid = $rowLVArt['id'];
                      if ($mainlocations[$nook] != NULL) {
                      echo "<option name='id' ";
                      echo "value='".$LOC_itemid.":".$LOC_title_alias."&authid=".$mainid[$nook]."'";
                      echo ">";
                      echo $mainlocations[$nook];
                      echo "</option>";
                      }
                    }
                ?>
          </select>
          </td><td valign="top" style="padding-right:6px;" height="23">
            <input type="button" name="go2" value="Go" id="link_go_b" onclick="this.form.submit()" />
          </form>
        </td>

 

I can't figure out how to disable the buttons so that the selection has to be made before you can click it.  I really want to avoid the 'Go' button being pressed when the dropdown is on the first item, ie 'Select Evangelist' or 'Select Location'  so if you do select a person/location, the 'Go' is active, then if you select 'Select ...' then the button de-activates so to speak.  Any help/ideas?  :confused:

 

NOTE: I have only got as far as trying to get this to work on the first dropdown - my thinking is I get it working on one, then I can mod it to work on the other  :D

Archived

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

×
×
  • Create New...

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.