File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes combo and text box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "combo and text box" Watch "combo and text box" New topic
Author

combo and text box

Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
i want my textbox to be activated whenever i select the "others" value in my combo box, without having to submit a form

how to do that?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
basic idea:
onchange="document.formName.elementName.disabled=(this.value!=-2)"

Eric
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
Originally posted by Eric Pascarello:
basic idea:
onchange="document.formName.elementName.disabled=(this.value!=-2)"

Eric


i replaced formName with the form's name and elementName with the textbox's name and placed it inside my select tag.
nothing happened

also, by defaul, i set my textbox to readonly="yes"
[ March 02, 2006: Message edited by: shuini gustav ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

<select name="mySelect" onchange="document.myForm.myText.disabled=(this.value!='others');document.myForm.myText.readOnly=false">

Don't know if this works will all browsers...


[My Blog]
All roads lead to JavaRanch
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
Originally posted by Satou kurinosuke:
<select name="mySelect" onchange="document.myForm.myText.disabled=(this.value!='others');document.myForm.myText.readOnly=false">

Don't know if this works will all browsers...


i'm using IE
this is my textbox
<input type="text" name="samplesize" readonly="yes" class="textbox" size="12">

and my combo
<select name="sample" class="textbox" onChange="document.mainform.samplesize.disabled=(this.value!='Others');document.mainform.samplesize.readOnly=false" style="width:100px;">
<option>1</option>
<option>2</option>
<option>Others</option>
</select>

doesn't work
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
why doesn't this work?

in the head part, i placed:
<script language="javascript">
function enableField()
{
document.myformname.mytextboxname.disabled=false;
}
</script>

and in the body:
<a href="javascript:enableField()">Click here to enable the element<a/>
<input type="text" name="mytextboxname" disabled="true">
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You forgot the form:

Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
i didn't, that was just assuming i already had the form.
why isn't this working?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

don't know You mean the html I have posted doesn't work ?
It works for me.
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
it was weird
it's working now. i just placed the form tags nearer my textbox.
but it's not supposed to matter,right?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

The form matters. I don't know what you mean by 'nearer' though
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Well if you looked at my code, you would see it is looking for a value.

(this.value!=-2)

If you would give it a value of -2 it would work.

or you could change it to

(this.text!='Others')

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: combo and text box
 
Similar Threads
Retaining JCombo values
need ajax code
Combo Box
Separator in combo box
Handling Chinese characters while retriving fromDB using JDBC