ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

conditional selection question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • conditional selection question

    I am running into a HTML problem with regards to my selection value.
    ctprivc = 002 but my screen value on the screen is always showing allow mail.

    Why is this happening.

    Here is my html code?

    </tr>

    <tr id="ContactPrivacyRow" class="ContactData">
    <td id="ContactPrivacyText" class="promptright">
    Privacy :&nbsp;
    </td>
    <td id="ContactPrivacyData" class="textleft">
    <span id="ContactPrivacy" class="checkbox">
    <select size="1"
    name="ctprivc" id="ctprivc"
    onchange="setContactFlag();">
    <option value="001">allow mail</option>
    <option value="002">no mail</option>
    </select>
    </span>
    &nbsp;
    <span id="ContactUseEMailText" class="promptright">
    Use E-Mail :
    </span>
    &nbsp;
    <span id="ContactUseEMailData">
    <select size="1"
    name="ctecf" id="ctecf"
    onchange="setContactFlag();">
    <option value="Y">Yes</option>
    <option value="N">No</option>
    </select>
    </span>
    </td>
    </tr>

  • #2
    Re: conditional selection question

    Are you using any other technology to build the page - PHP etc, as you may need to check the value of the existing option and change which item is highlighted as selected. By default the first item will be selected and if the "setContactFlag" script redraws the page then it will again reset it to the first option.

    need to see the code for setContactFlag()
    Last edited by gcraill; October 23, 2013, 04:05 AM.
    Greg Craill: "Life's hard - Get a helmet !!"

    Comment


    • #3
      Re: conditional selection question

      Something like this ...

      PHP Code:
      <?PHP
      if (isset($_REQUEST['ctp'])) { 
          
      $CurValue $_REQUEST['ctp'];  
      } else { 
          
      $CurValue '002';  

      ?>

      <script language="javascript" type="text/javascript">
      <!--
      function setContactFlag) 
      {
       var x=document.getElementById("ctprivc");
       window.location = "your_page.php?ctp="+x.value
      }
      //-->
      </script>

      <select size="1" name="ctprivc" id="ctprivc" onchange="setContactFlag();">
        <?PHP
        
      if ($CurValue == '001') { 
           echo 
      "<option value='001' selected>Allow mail</option>"
        } else {  
           echo 
      "<option value='001'>Allow mail</option>";
        }
        if (
      $CurValue == '002') { 
           echo 
      "<option value='002' selected>No Mail</option>"
        } else { 
           echo 
      "<option value='002'>No Mail</option>";
        }
        
      ?>
      </select>
      Last edited by gcraill; October 23, 2013, 04:21 AM.
      Greg Craill: "Life's hard - Get a helmet !!"

      Comment


      • #4
        Re: conditional selection question

        The HTML code that dcutaia posted does not have any of the options selected. The way an option is selected is by adding the 'selected' attribute to the option tag, as gcraill posted in his PHP example.
        Code:
        <option value="002" [B]selected[/B]>no mail</option>
        So not sure what dcutaia means when he says "ctprivc = 002". It certainly doesn't appear to be set to 002 in the example you posted?! But, maybe it's set in some JavaScript somewhere? If so, please post that JavaScript. (It can't be in the onchange= routine, since that would only fire if the user made a change to the value by hand.) Or, can you explain what you mean by "ctprivc = 002"?

        Comment

        Working...
        X