0

I want to hide textbox control using javascript or jquery.I have used javascript

document.getElementsByName('Custom_Field_Custom1').style.display="none";

java console shows me this error :

document.getElementsByName('Custom_Field_Custom1').style.display="none" is undefined.

Please help me

1
  • Notice the plurality in the method getElementsByName. That indicates we are being returned an array. Loop it or pull the first item from it. Commented Sep 27, 2011 at 6:41

4 Answers 4

3

getElementsByName returns an array. You either want to use an ID and call getElementById, or use getElementsByName('Custom_Field_Custom1')[0].

Sign up to request clarification or add additional context in comments.

1 Comment

It returns a NodeList, not an Array. They are only superficially similar.
2

getElementsByName returns a NodeList not an HTMLElementNode. It doesn't have a style property, so you get the error because undefined.display isn't allowed.

Loop over the NodeList as if it was an array.

1 Comment

thanks I have used document.getElementsByName('Custom_Field_Custom1')[0].style.display="none";
2

$('input:text') would select all textboxes in the page.

Hence, $('input:text').hide(); would hide all your textboxes.

If you need to hide a single textbox you can give it an id, as in <input type="text" id="Custom_Field_Custom1" />

$('#Custom_Field_Custom1').hide(); would then hide that single one.

2 Comments

ok,but why I am getting document.getElementsByName('Custom_Field_Custom1').style.display="none" is undefined. ?
That would match <Custom_Field_Custom1> elements, which aren't allowed in HTML.
1

Well seems all the possible answer comes here. I just simplified the answer :

for change CSS with jquery use following code :

$('#Custom_Field_Custom1').css('display','none');

For hide the text box with jquery use following code :

$('#Custom_Field_Custom1').hide();

In both case remember one thing here "Custom_Field_Custom1" must be id of the textbox.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.