Reply
Enable a text field when user selects other from drop down
Old 05-02-2006, 12:34 AM Enable a text field when user selects other from drop down
reli4nt's Avatar
Extreme Talker

Posts: 153
Location: New York
Can anyone point me in the right direction to figure this one out? I have seen it doen a million times but now I can't seem to find any examples, and everything Ive tried thus far has ended up lame.
__________________
The JPProject Multimedia
Designing the world we live in.
Defining the terms we live by.
reli4nt is offline
Reply With Quote
View Public Profile Visit reli4nt's homepage!
 
When You Register, These Ads Go Away!
Old 05-02-2006, 09:48 AM Re: Enable a text field when user selects other from drop down
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
document.myform.textfield_id.disabled = false;

Assuming your using a form that is. The form name and id would be 'myform' the textfie ld would be the 'textfield_id'.

Initially you could make this disabled by default so that when you have your selection you then call document.myform.textfield_id.disabled = false; and it will be active.

Might take a tinkering or two but it should be fine.

Ibbo
__________________
www.nationalclubgolfer.com www.sportspub.co.uk www.bespokecc.co.uk www.centralmarquees.co.uk
Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 05-02-2006, 04:07 PM Re: Enable a text field when user selects other from drop down
reli4nt's Avatar
Extreme Talker

Posts: 153
Location: New York
Thanks, I think I get that part.

I'm having trouble understanding how to affect one with the other.

In the option tags of the drop down I put
Code:
 onchange="enableother()"
then I made a simple function to "allegedly" switch the value of the input field

Code:
function enableother()
{
    if (document.formname.selectname == 'other')
    {
        document.formname.fieldname.disable = false
    }
    else
    {
        document.formname.fieldname.disable = true
    }
}
of course the whole thing just ignores me and I'm not entirely sure why. Sorry for being such a n00b but I really don't understand the logic behind JavaScript yet.

Anyone know what I'm missing and why?
__________________
The JPProject Multimedia
Designing the world we live in.
Defining the terms we live by.

Last edited by reli4nt : 05-02-2006 at 04:08 PM.
reli4nt is offline
Reply With Quote
View Public Profile Visit reli4nt's homepage!
 
Old 05-03-2006, 02:09 PM Re: Enable a text field when user selects other from drop down
funkdaddu's Avatar
Web Design Snob

Posts: 636
This should work for what you want:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Untitled Page</title>
		<script type="text/javascript"><!--
function dropdown(option) {
	if (option == "name") {
		document.FormName.textfieldName.disabled = false;
	} else {
		document.FormName.textfieldName.disabled = true;
	}
}
//-->
</script>
	</head>

	<body bgcolor="#ffffff">
		<form id="FormName" action="" method="get" name="FormName">
			<select name="selectName" size="1" onchange="dropdown(this.value);">
				<option>Choose...</option>
				<option value="name">Your Name</option>
				<option value="age">Your Age</option>
			</select> <input type="text" name="textfieldName" disabled size="24">
		</form>
	</body>

</html>
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 05-03-2006, 02:20 PM Re: Enable a text field when user selects other from drop down
reli4nt's Avatar
Extreme Talker

Posts: 153
Location: New York
AHA! You got it. Thanks.

I see I was on the right track at least.

So "this" is automatic resource in JavaScript?

In someway s JS is so similar to php but the context, or the environment, feels so foreign to me.

So simple too.

Thanks again!
__________________
The JPProject Multimedia
Designing the world we live in.
Defining the terms we live by.
reli4nt is offline
Reply With Quote
View Public Profile Visit reli4nt's homepage!
 
Reply     « Reply to Enable a text field when user selects other from drop down
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14779 seconds with 12 queries