SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with Javascript code

    I have a DDL with "other" as an option. If Other is selected the textbox appears. If someone tries to submit the form I want an error message to appear.

    What am I doing wrong or is there another way to do this?


    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <style type="text/css">
    .hidden {
    display: none;
    }
    </style>
    <title>Untitled Page</title>
    <script type="text/javascript">

    function enableOther()
    {
    if (!document.getElementById) return;
    var s = document.getElementById('reason1');
    if (!s) return;
    if (s.options[s.selectedIndex].value != 'Other: ') return;
    var t = document.getElementById('reason1other');
    if (!t) return;
    t.disabled = false;
    t.className = '';
    }

    function init()
    {
    if (!document.getElementById) return;
    var s = document.getElementById('reason1');
    if (!s) return;
    s.onchange = enableOther;
    var t = document.getElementById('reason1other');
    if (!t) return;
    t.disabled = true;
    t.className = 'hidden';
    }

    window.onload = init;
    </script>

    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <form>
    <select id="reason1" name="reason1">
    <option value="P.T.">P.T.</option>
    <option value="Break">Break</option>
    <option value="IT">IT Issues</option>
    <option value="Training">Training</option>
    <option value="Briefing">Briefing</option>
    <option value="Supervisor">Supervisor</option>
    <option value="Other: ">Other</option>
    </select>
    <input type="text" id="reason1other" name="reason1other" Size=22 />
    </form>
    </div>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="enableOther();" />
    </form>
    </body>
    </html>

    Thanks!

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jj297 View Post
    What am I doing wrong or is there another way to do this?
    Just to rule out an obvious problem, can you show us what the ASP code looks like as HTML code, once it's been given to the web browser?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry I don't know what you mean.

    Do you mean to make the page an html page with a dropdown box?

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jj297 View Post
    I'm sorry I don't know what you mean.
    Here is what I mean. The cause for your problem is not obvious, and some of us do not have an environment that can compile ASP code. Since JavaScript works only with the HTML code that is given to the web browser, you will receive the best help if you can provide a sample test page that demonstrates the problem, because then we can load it up locally, play around with it, and work out what is going wrong for you.

    If you cannot provide a link to a test page that demonstrates the problem, the next best thing you can do is to provide HTML code that can allow us to experience the same problem that you're having.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Something that you may first want to investigate though, is that forms must not be nested within each other. That's just not allowed.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay I understand. I need this to work with aspx code as the entire page is set up that way. I thought what I sent was ample enough to be placed into an html page and it will come up as to what I have on my page. I took the code and placed it in an html page and it came up.

    Thanks don't worry about it I will try to get the customvalidator to work in asp.net. Thanks anyway.


Bookmarks

Posting Permissions

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