h8ids 05-04-2006, 10:29 PM 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?
<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>
Beagle 05-04-2006, 10:31 PM 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.
boxxer03 05-04-2006, 11:28 PM 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
h8ids 05-05-2006, 05:19 PM Got it!
Thanks guys :thumbsup:
h8ids 05-05-2006, 05:40 PM 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:
<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>
Beagle 05-05-2006, 06:37 PM CASE SENSITIVITY!!!!
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:
<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>
h8ids 05-05-2006, 07:07 PM Beagle,
Fixed the Case sensitivity. But the testDD field still isn't working correctly.
Seems the following code is being ignored:
if (elementid=='Full - 4 Semester Hours')
document.getElementById('testDD').disabled=true;
Beagle 05-05-2006, 07:12 PM 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.
h8ids 05-05-2006, 08:22 PM 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"
<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>
Beagle 05-05-2006, 08:28 PM try elementId.id?
arnyinc 05-05-2006, 08:42 PM is this what you want it to do?
<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>
Beagle 05-05-2006, 08:46 PM right, elementId.value, sorry, tired:rolleyes:
h8ids 05-05-2006, 08:51 PM Are you suggesting element.id?
or asking if I had tried element.id
try elementId.id?
Beagle 05-05-2006, 09:05 PM you need to compare the value of the element to the string, not the element itself:
(elementId.value == 'Full Course - etc')
h8ids 05-05-2006, 09:18 PM I see now.
I wasn't breaking down, what I had in mind, enough.
It works now.
Thanks for your help.
you need to compare the value of the element to the string, not the element itself:
(elementId.value == 'Full Course - etc')
|
|