Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-04-2006, 10:29 PM   PM User | #1
h8ids
Regular Coder

 
Join Date: Jan 2006
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
h8ids is an unknown quantity at this point
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>
h8ids is offline   Reply With Quote
Old 05-04-2006, 10:31 PM   PM User | #2
Beagle
Senior Coder

 
Join Date: Jul 2005
Location: New York, NY
Posts: 1,084
Thanks: 4
Thanked 19 Times in 19 Posts
Beagle is an unknown quantity at this point
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.
Beagle is offline   Reply With Quote
Old 05-04-2006, 11:28 PM   PM User | #3
boxxer03
Regular Coder

 
Join Date: Sep 2005
Location: Chicago, IL
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
boxxer03 is an unknown quantity at this point
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. ;)
boxxer03 is offline   Reply With Quote
Old 05-05-2006, 05:19 PM   PM User | #4
h8ids
Regular Coder

 
Join Date: Jan 2006
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
h8ids is an unknown quantity at this point
Smile

Got it!

Thanks guys
h8ids is offline   Reply With Quote
Old 05-05-2006, 05:40 PM   PM User | #5
h8ids
Regular Coder

 
Join Date: Jan 2006
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
h8ids is an unknown quantity at this point
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>
h8ids is offline   Reply With Quote
Old 05-05-2006, 06:37 PM   PM User | #6
Beagle
Senior Coder

 
Join Date: Jul 2005
Location: New York, NY
Posts: 1,084
Thanks: 4
Thanked 19 Times in 19 Posts
Beagle is an unknown quantity at this point
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>
Beagle is offline   Reply With Quote
Old 05-05-2006, 07:07 PM   PM User | #7
h8ids
Regular Coder

 
Join Date: Jan 2006
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
h8ids is an unknown quantity at this point
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;
h8ids is offline   Reply With Quote
Old 05-05-2006, 07:12 PM   PM User | #8
Beagle
Senior Coder

 
Join Date: Jul 2005
Location: New York, NY
Posts: 1,084
Thanks: 4
Thanked 19 Times in 19 Posts
Beagle is an unknown quantity at this point
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.
Beagle is offline   Reply With Quote
Old 05-05-2006, 08:22 PM   PM User | #9
h8ids
Regular Coder

 
Join Date: Jan 2006
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
h8ids is an unknown quantity at this point
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>
h8ids is offline   Reply With Quote
Old 05-05-2006, 08:28 PM   PM User | #10
Beagle
Senior Coder

 
Join Date: Jul 2005
Location: New York, NY
Posts: 1,084
Thanks: 4
Thanked 19 Times in 19 Posts
Beagle is an unknown quantity at this point
try elementId.id?
Beagle is offline   Reply With Quote
Old 05-05-2006, 08:42 PM   PM User | #11
arnyinc
Regular Coder

 
Join Date: Jan 2003
Posts: 867
Thanks: 4
Thanked 8 Times in 8 Posts
arnyinc is an unknown quantity at this point
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>
arnyinc is offline   Reply With Quote
Old 05-05-2006, 08:46 PM   PM User | #12
Beagle
Senior Coder

 
Join Date: Jul 2005
Location: New York, NY
Posts: 1,084
Thanks: 4
Thanked 19 Times in 19 Posts
Beagle is an unknown quantity at this point
right, elementId.value, sorry, tired
Beagle is offline   Reply With Quote
Old 05-05-2006, 08:51 PM   PM User | #13
h8ids
Regular Coder

 
Join Date: Jan 2006
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
h8ids is an unknown quantity at this point
Question

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

Quote:
Originally Posted by Beagle
try elementId.id?
h8ids is offline   Reply With Quote
Old 05-05-2006, 09:05 PM   PM User | #14
Beagle
Senior Coder

 
Join Date: Jul 2005
Location: New York, NY
Posts: 1,084
Thanks: 4
Thanked 19 Times in 19 Posts
Beagle is an unknown quantity at this point
you need to compare the value of the element to the string, not the element itself:

(elementId.value == 'Full Course - etc')
Beagle is offline   Reply With Quote
Old 05-05-2006, 09:18 PM   PM User | #15
h8ids
Regular Coder

 
Join Date: Jan 2006
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
h8ids is an unknown quantity at this point
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 09:34 PM..
h8ids is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:37 PM.


Advertisement
Log in to turn off these ads.