Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Enable/Disable Form Elements Help

    I currently have the following code in a page. (I've removed some of the stuff not critical to this question) I am attempting to keep the LinkOption box disabled (grayed) unless the user selects "ExternalLink" from the "required_commentnature" box.

    Any help would be appreciated. Allen.


    ------>START CODE<------
    <html>

    <head>
    <script language="Javascript"><!--
    function enable_element ()
    {
    var x=document.getElementbyID("required_commentnature").selectedIndex
    var y=document.GetElementsbyTagName("required_commentnature"[x].value
    if y="ExternalLink" then (document.getElementbyID("LinkOption").disabled=false)

    }
    </script>

    <title>Website Response Form</title>
    </head>

    <body>

    <form method="POST" name="WebsiteCommentForm" action="--WEBBOT-SELF--" onSubmit="location.href='_derived/nortbots.htm';return false;" webbot-onSubmit>

    <p style="margin-top: 0; margin-bottom: 4">Name:&nbsp;
    <input type="text" name="required_Name" size="50" tabindex="1"></p>

    <p style="margin-top: 0; margin-bottom: 4">Email Address:&nbsp;
    <input type="text" name="required_Address" size="50" tabindex="2"></p>

    <p align="left" style="margin-top: 0; margin-bottom: 4">Nature of Comment:&nbsp;

    <select size="1" name="required_commentnature" tabindex="3" onChange="enable_element()">

    <option value="None">No Choice Selected Yet</option>
    <option value="TeacherPage">Content of Teacher Page(s)</option>
    <option value="GeneralPage">Content of General Page(s)</option>
    <option value="ExternalLink">External Link(s) from Website</option>
    <option value="General">General Site Comment(s)</option>
    </select></p>

    <p align="left" style="margin-top: 0; margin-bottom: 4">If Commenting on external links, please specify nature:

    <select size="1" name="LinkOption" tabindex="4" disabled="true">

    <option>No Choice Selected</option>
    <option>External link is broken (does not link to an existing page)</option>
    <option>Content of linked page is inappropriate</option>
    <option>External link has outdated or incorrect information</option>
    <option>Positive comment on external link</option>
    </select></p>

    <p align="left" style="margin-top: 0; margin-bottom: 4">If you are commenting on an external link, please indicate the page from which the link is from and the page to which it is linking.</p>
    <p align="left" style="margin-top: 0; margin-bottom: 4">Comments:</p>
    <p align="left" style="margin-top: 0; margin-bottom: 4">
    <textarea rows="6" name="comments" cols="80" tabindex="5"></textarea></p>
    <p align="center">
    <input type="submit" value="Submit" name="submit" tabindex="10"><input type="reset" value="Reset" name="reset" tabindex="11"></p>
    </form>

    </body></html>

    ----->END OF CODE<----

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    1. First, you should be aware that language is deprecated. Use type instead.
    2. Secondly, JS is case sensitive:
      Code:
      document.getElementbyID
      .
      .
      .
      document.GetElementsbyTagName
      ...should be:
      Code:
      document.getElementById
      .
      .
      .
      document.getElementsByTagName
    3. Javascript syntax for if statements is not the same as that of vbscript's if then. This part is erroneous:
      Code:
      if y="ExternalLink" then (document.getElementbyID("LinkOption").disabled=false)
      And should be:
      Code:
      if(y=='ExternalLink")
      	// Action
    4. And lastly, you have incomplete comment line:
      Code:
      <!--
      <script.....
      .
      .
      .
      // -->
      </script>
      You miss highlighted.



    You might find this complete ammendment useful:
    Code:
    <script type="text/javascript">
    <!--
    function enable_element()
    {
    var x=document.getElementsByName("required_commentnature")[0],
    y=document.getElementsByName("LinkOption")[0];
    y.disabled=x.value=='ExternalLink'?false:true;
    }
    -->
    </script>
    P.S., you can also use document.getElementById in replacement of document.getElementsByTagName. Just ensure to add an id attribute on the select element.

    Hope that helps.
    Last edited by rangana; 10-16-2008 at 02:48 AM.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •