Enjoy an ad free experience by logging in. Not a member yet?
Register .
05-04-2006, 10:29 PM
PM User |
#1
Regular Coder
Join Date: Jan 2006
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
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--> <b>Other specification:</b>
<input disabled value="dvdv" type="Text" id='testDD' size="40" maxlength="100" name="OtherCredit"></form>
05-04-2006, 10:31 PM
PM User |
#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.
05-04-2006, 11:28 PM
PM User |
#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. ;)
05-05-2006, 05:19 PM
PM User |
#4
Regular Coder
Join Date: Jan 2006
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
Got it!
Thanks guys
05-05-2006, 05:40 PM
PM User |
#5
Regular Coder
Join Date: Jan 2006
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
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>
05-05-2006, 06:37 PM
PM User |
#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(elementI d, thiselement){
document.form1.Credit.disabled = !document.form1.Credit.disabled;
document.form1.testDD.disabled = !document.form1.testDD.disabled;
if (elementi d=='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>
05-05-2006, 07:07 PM
PM User |
#7
Regular Coder
Join Date: Jan 2006
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
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;
05-05-2006, 07:12 PM
PM User |
#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.
05-05-2006, 08:22 PM
PM User |
#9
Regular Coder
Join Date: Jan 2006
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
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>
05-05-2006, 08:28 PM
PM User |
#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?
05-05-2006, 08:42 PM
PM User |
#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>
05-05-2006, 08:46 PM
PM User |
#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
05-05-2006, 08:51 PM
PM User |
#13
Regular Coder
Join Date: Jan 2006
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
Are you suggesting element.id?
or asking if I had tried element.id
Quote:
Originally Posted by Beagle
try elementId.id?
05-05-2006, 09:05 PM
PM User |
#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')
05-05-2006, 09:18 PM
PM User |
#15
Regular Coder
Join Date: Jan 2006
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
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 09:34 PM ..
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 08:37 PM .
Advertisement
Log in to turn off these ads.