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 15 of 15
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Field disables but won't re-enable.

    Fields dynamically populated from database.
    Both listbox and textbox should be disabled initially.
    Text link re-activates both listbox and textbox.
    Text box only needs to be active when "Other - Please Specify" is chosen.
    If one of the other two listbox options are chosen, the textbox value empties and it should become disabled.
    If "Other - Please Specify" is selected again, the textbox should re-activate.

    Been working on this for a couple of days.
    Everything about the process works except for the textbox becoming disabled.
    I don't think there's anything wrong with "function enableQ3()" since the text link reliably works.
    I'm running into problems with "function swapQ3".
    What am I missing?

    Code:
    <script>function enableQ3(){
      document.form1.Credit.disabled = !document.form1.Credit.disabled;
      document.form1.testDD.disabled = !document.form1.testDD.disabled;
    }
    function swapQ3(elementid, thiselement){
    	if (elementid=="Other - Please Specify") {
    		document.getElementById('testDD').enabled; }
    		else (elementid=="Full - 4 Semester Hours") || (elementid=="Half - 2 Semester Hours")
    		document.getElementById('testDD').disabled="disabled";
    		document.getElementById('testDD').value=''; } </script>
    
    <form name="form1">
    <a onmousedown="enableQ3();" href="javascript:void(0);">Credit?</a>
    <select disabled name='Credit' onchange="swapQ3(this.value, 'testDD')">
    <option value="Other - Please Specify">Other - Please Specify</option>
    <option value='Full Course - 4 Semester Hours'>Full Course - 4 Hours
    <option value='Half Course - 2 Semester Hours'>Half Course - 2 Hours</select><br>
    <!--Other course credit specified-->&nbsp;&nbsp;&nbsp;&nbsp;<b>Other specification:</b>
    <input disabled value="dvdv" type="Text" id='testDD'  size="40" maxlength="100" name="OtherCredit"></form>

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    well, two things

    don't set disabled to "disabled", set it true (in the javascript, not the html)

    and .enabled doesn't exist. either it's disabled true or false.

  • #3
    Regular Coder
    Join Date
    Sep 2005
    Location
    Chicago, IL
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    and just a quick note so you know (incase you don't), whenever you set it to true or false don't put quotations around true or false just set it like: document.getElementById(id).disabled=true
    I'm only telling you how I would do it, not how its supposed to be done. ;)

  • #4
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Got it!

    Thanks guys

  • #5
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Running into an "elementID is not defined" error.
    Everything is running fine, EXCEPT the testDD field is failing to disable.
    I want both fields to be disabled when 'Full - 4 Semester Hours' is selected and the "Credit?" button is selected.
    Thought I had it... Newbie blues.


    Here's the code:
    Code:
    <script>
    function enableQ3(elementId, thiselement){
      document.form1.Credit.disabled = !document.form1.Credit.disabled;
      document.form1.testDD.disabled = !document.form1.testDD.disabled;
    	if (elementid=='Full - 4 Semester Hours')
    		document.getElementById('testDD').disabled=true;
    }
    function swapQ3(elementid, thiselement){
    	if (elementid=='Other - Please Specify')
    		document.getElementById(thiselement).disabled=false;
    	else
    		document.getElementById(thiselement).disabled=true;
    		document.getElementById(thiselement).value='';
    }
    
    <form name="form1">
    3.
    <a onmousedown="enableQ3();" title="Activate / Deactivate" href="javascript:void(0);">Credit?</a> 
    
    <select disabled name='Credit' onchange="swapQ3(this.value, 'testDD')">
    <option value='Other - Please Specify'>Other - Please Specify</option>
    <option value='Full Course - 4 Semester Hours'>Full Course - 4 Semester Hours
    <option value='Half Course - 2 Semester Hours'>Half Course - 2 Semester Hours
    <option value='Other - Please Specify'>Other - Please Specify </select>
    </script>
    
    Other specification:
    <input disabled value="dvdv" type="Text" id='testDD' size="40" name="OtherCredit"><p></form>

  • #6
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    CASE SENSITIVITY!!!!

    Quote Originally Posted by h8ids
    Running into an "elementID is not defined" error.
    Everything is running fine, EXCEPT the testDD field is failing to disable.
    I want both fields to be disabled when 'Full - 4 Semester Hours' is selected and the "Credit?" button is selected.
    Thought I had it... Newbie blues.


    Here's the code:
    Code:
    <script>
    function enableQ3(elementId, thiselement){
      document.form1.Credit.disabled = !document.form1.Credit.disabled;
      document.form1.testDD.disabled = !document.form1.testDD.disabled;
    	if (elementid=='Full - 4 Semester Hours')
    		document.getElementById('testDD').disabled=true;
    }
    function swapQ3(elementid, thiselement){
    	if (elementid=='Other - Please Specify')
    		document.getElementById(thiselement).disabled=false;
    	else
    		document.getElementById(thiselement).disabled=true;
    		document.getElementById(thiselement).value='';
    }
    
    <form name="form1">
    3.
    <a onmousedown="enableQ3();" title="Activate / Deactivate" href="javascript:void(0);">Credit?</a> 
    
    <select disabled name='Credit' onchange="swapQ3(this.value, 'testDD')">
    <option value='Other - Please Specify'>Other - Please Specify</option>
    <option value='Full Course - 4 Semester Hours'>Full Course - 4 Semester Hours
    <option value='Half Course - 2 Semester Hours'>Half Course - 2 Semester Hours
    <option value='Other - Please Specify'>Other - Please Specify </select>
    </script>
    
    Other specification:
    <input disabled value="dvdv" type="Text" id='testDD' size="40" name="OtherCredit"><p></form>

  • #7
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Beagle,

    Fixed the Case sensitivity. But the testDD field still isn't working correctly.
    Seems the following code is being ignored:

    Code:
    	if (elementid=='Full - 4 Semester Hours')
    		document.getElementById('testDD').disabled=true;

  • #8
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    Instead of thinking that the line is being ignored, try to figure out why elementid != 'Full - 4 Semester Hours'

    Alert elementid before comparing it, make sure things are as you believe them to be. Your code is dependent on this conditional, and if it's false, it won't happen. It's behaving as you have told it to. You need to rephrase yourself so it better understands.

  • #9
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Beagle,

    I don't see what I'm missing. And I know I'm thoroughly confused at the moment.

    The following produces this alert message:
    "objectHTMLSelectElement"

    Plus I'm getting an error, using Firefox's Firebug plugin.
    "assignment to undeclared variable value"

    Code:
    <script>
    function enableQ3(elementId, thiselement){
    document.form1.Credit.disabled = !document.form1.Credit.disabled;
    document.form1.testDD.disabled = !document.form1.testDD.disabled;
    elementId=document.form1.Credit
    if (elementId=='Full Course - 4 Semester Hours')
    document.getElementById('testDD').disabled=true;
    alert(value=elementId)
    }
    function swapQ3(elementId, thiselement){
    	if (elementId=='Other - Please Specify')
    		document.getElementById(thiselement).disabled=false;
    	else
    		document.getElementById(thiselement).disabled=true;
    		document.getElementById(thiselement).value='';
    }
    </script>
    <form name="form1">
    <a onmousedown="enableQ3();" title="Activate / Deactivate" href="javascript:void(0);">Credit?</a> 
    
    <select disabled name='Credit' onchange="swapQ3(this.value, 'testDD')">
    <option value='Other - Please Specify'>Other - Please Specify</option>
    <option value='Full Course - 4 Semester Hours'>Full Course - 4 Semester Hours
    <option value='Half Course - 2 Semester Hours'>Half Course - 2 Semester Hours
    <option value='Other - Please Specify'>Other - Please Specify </select>
    
    Other specification:
    <input disabled value="dvdv" type="Text" id='testDD' size="40" name="OtherCredit"><p></form>

  • #10
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    try elementId.id?

  • #11
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    is this what you want it to do?

    Code:
    <script>
    function enableQ3(elementId, thiselement){
    document.form1.Credit.disabled = !document.form1.Credit.disabled;
    document.form1.testDD.disabled = !document.form1.testDD.disabled;
    elementId=document.form1.Credit
    if (elementId=='Full Course - 4 Semester Hours')
    document.getElementById('testDD').disabled=true;
    alert(elementId.value)
    }
    function swapQ3(elementId, thiselement){
    	if (elementId=='Other - Please Specify')
    		document.getElementById(thiselement).disabled=false;
    	else{
    		document.getElementById(thiselement).disabled=true;
    		document.getElementById(thiselement).value='';
    	}
    }
    </script>
    <form name="form1">
    <a onmousedown="enableQ3();" title="Activate / Deactivate" href="javascript:void(0);">Credit?</a> 
    
    <select disabled name='Credit' onchange="swapQ3(this.value, 'testDD')">
    <option value='Other - Please Specify'>Other - Please Specify</option>
    <option value='Full Course - 4 Semester Hours'>Full Course - 4 Semester Hours
    <option value='Half Course - 2 Semester Hours'>Half Course - 2 Semester Hours
    <option value='Other - Please Specify'>Other - Please Specify </select>
    
    Other specification:
    <input disabled value="dvdv" type="Text" id='testDD' size="40" name="OtherCredit"><p></form>

  • #12
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    right, elementId.value, sorry, tired

  • #13
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Are you suggesting element.id?
    or asking if I had tried element.id

    Quote Originally Posted by Beagle
    try elementId.id?

  • #14
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    you need to compare the value of the element to the string, not the element itself:

    (elementId.value == 'Full Course - etc')

  • #15
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    I see now.
    I wasn't breaking down, what I had in mind, enough.

    It works now.
    Thanks for your help.


    Quote Originally Posted by Beagle
    you need to compare the value of the element to the string, not the element itself:

    (elementId.value == 'Full Course - etc')
    Last edited by h8ids; 05-05-2006 at 10:34 PM.


  •  

    Posting Permissions

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