Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6929343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:18:17+00:00 2026-05-27T11:18:17+00:00

I want this script to disable date fields when the page loads, then enable/disable

  • 0

I want this script to disable date fields when the page loads, then enable/disable depending on the drop down field. The script simply isnt doing anything, was wondering if anyone can see what I am doing wrong.

    <head>
    function formdisable(){
    var myTextField = document.getElementById('searchby');
if(myTextField.value = "agencyname")
    document.searchform.Date1.disabled=true
    document.searchform.Date2.disabled=true
    document.searchform.agencyname.disabled=false
else
    document.searchform.Date1.disabled=false
    document.searchform.Date2.disabled=false
    document.searchform.agencyname.disabled=true
    }
    onload = start;
    </script>
    </head>
    <table>
    <form id="searchform" name="searchform"> 
    <tr>
    <td>Search Term: </td><td><input tabindex="1" type="text" name="search" id="search1"        value=""  /></td>
    </tr>
    <tr><td>Search By:</td><td><select size="1"  id="searchby" name="searchby" onclick="formdisable()" tabindex="2">
<option value="agencyname">Agency Name</option>
<option value="daterange">Date Range</option>
    </select></td></tr>
    <tr>
    <td>Beginning Date: </td><td><input  id="Date1" name="Date1" size="10"   maxlength="10" value="<?php echo $_GET['Date1']?>"/> </td><td>Ending Date: </td><td><input   id="Date2" name="Date2" size="10" maxlength="10" value="<?php echo $_GET['Date2'];?>" />          </td></tr>
   <input type="hidden" id="wildcard" value="= 'Approved'" />  
   <input type="hidden" id="repid" value="<?php echo $_SESSION['REPID']; ?>" />  
   <tr><td><input tabindex="3" type='button' onclick='searchAgency()' name="searchsub"  value='Search' /></td></tr></td>
   </tr>
   </form>
   </table>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:18:18+00:00Added an answer on May 27, 2026 at 11:18 am

    Right away, I see missing {} in your if/else, and an assignment = where an equality == belongs:

    if(myTextField.value = "agencyname")
        document.searchform.Date1.disabled=true
        document.searchform.Date2.disabled=true
        document.searchform.agencyname.disabled=false
    else
        document.searchform.Date1.disabled=false
        document.searchform.Date2.disabled=false
        document.searchform.agencyname.disabled=true
    

    Should probably be:

    <script type='text/javascript>
    //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    // Forgot the opening script tag
    

    Then…

    if(myTextField.value == "agencyname") {
        //-------------^^^^^^^
        // ==, not =
        document.searchform.Date1.disabled=true;
        // Please manually insert semicolons--^^^
        document.searchform.Date2.disabled=true;
        document.searchform.agencyname.disabled=false;
    }
    else {
        document.searchform.Date1.disabled=false;
        document.searchform.Date2.disabled=false;
        document.searchform.agencyname.disabled=true;
    }
    

    In your original version, you were assigning agencyname to myTextField.value inside the if() condition. Followed by that was a mess of partially executed code. The assignment would succeed, and then the first (and only the first) subsequent statement would execute as part of the if() block. The next two would execute before coming to a syntax error on the else.

    You are relying on automatic semicolon insertion, which is a dangerous (mis-)feature of the JavaScript language when used recklessly. Please always terminate your statements with ;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my site i want to set default page to open, using this script
in one page function i want disable js script. How make that? I try
I have a tab container in aspx page and i want to enable disable
I want to execute this script (view source) that uses Google Translate AJAX API
I want help on this script I am making... I want my website to
I have this script that collects data from users and I want to check
What I want to do with this script is to copy a file in
I want to start up my Rails development server like this: script/server OFFLINE_MODE=1 and
I have a file hosting site that's using this script MFHS . I want
I want something like this: <msxsl:script language=C#> ??? getNodes() { ... return ... }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.