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 08-30-2011, 08:37 PM   PM User | #1
jcdevelopment
Senior Coder

 
jcdevelopment's Avatar
 
Join Date: Oct 2007
Location: Cowboy Nation
Posts: 2,171
Thanks: 173
Thanked 257 Times in 257 Posts
jcdevelopment will become famous soon enoughjcdevelopment will become famous soon enough
Disabling a text field depending on 2 options

Not 100% sure why or how to make this work.

I have 5 options in a select drop-down. Only two of them are to disable a text field. I have written it successfully to disable on one option. How would I add the second option? I have tried many different ways, and i know its something small that i am missing.

Below is the code that does not work but shows the 2 options that disable my text field.

Code:
<script type="text/javascript">
    function type_disable() {
		var qr_type = document.getElementById('qr_type');
    var qr_owner = document.getElementById('qr_owner');
    if(qr_type.value == 'bio' || 'rebrand')
        qr_owner.disabled = true
    else
        qr_owner.disabled = false
}
	
</script>
Code:
<tr>
	
	<td align="right"><span class="re">*</span>Type: </td>
	<td align="left"> &nbsp;<select id="qr_type"  name="qr_type" onChange="type_disable()">
	
	<option value="0">Select Type</option>
		 <option value="property">Property Code</option> 
		 <option value="ipw">IPW Code</option> 
		 <option value="bio">Biography Code</option> 
		 <option value="rebrand">Rebrand Code</option> 
		 <option value="property_rebrand">Property-rebrand Code</option> 
		 </select>
	 
	 </td>
	<td ></td>
	</tr>

	
	<tr>
	
	<td align="right"><span class="re">*</span>Owner: </td>
	<td align="left"> &nbsp;<input type="textbox" name="qr_owner" id="qr_owner" size="30" value=""/></td>
	<td ></td>
	</tr>
Thanks for any help!
jcdevelopment is offline   Reply With Quote
Old 08-30-2011, 08:49 PM   PM User | #2
Tails
Regular Coder

 
Join Date: Nov 2002
Posts: 672
Thanks: 1
Thanked 1 Time in 1 Post
Tails is an unknown quantity at this point
The || separates statements, not values. Do this instead:

Code:
 if(qr_type.value == 'bio' || qr_type.value == 'rebrand')
It may be easier to assign numeric values to the options so that you check if the value is greater than 0.
Tails is offline   Reply With Quote
Users who have thanked Tails for this post:
jcdevelopment (08-30-2011)
Old 08-30-2011, 09:08 PM   PM User | #3
jcdevelopment
Senior Coder

 
jcdevelopment's Avatar
 
Join Date: Oct 2007
Location: Cowboy Nation
Posts: 2,171
Thanks: 173
Thanked 257 Times in 257 Posts
jcdevelopment will become famous soon enoughjcdevelopment will become famous soon enough
If only i got paid for my "brain farts"! thanks.
jcdevelopment is offline   Reply With Quote
Old 08-31-2011, 08:21 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
var qr_type = document.getElementById('qr_type');

Just a comment, be aware that in Internet Explorer, names and IDs are global variables and thus you should NEVER use a global variable or function name which is the same as an HTML element name or ID.

Here your variables are local, not global scope, but even so it is perhaps unwise or confusing to assign the same name.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Tags
disable, select, textfield

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 09:57 PM.


Advertisement
Log in to turn off these ads.