473,395 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to disable an text box when text box name is like arrfirst[0] using javascript

hi

i am trying to disable array item but its not working.please help me how to disable.
ex : index = 0;
arrfirst[index].disabled = false ;
Jun 5 '07 #1
6 2214
sumittyagi
202 Expert 100+
hi

i am trying to disable array item but its not working.please help me how to disable.
ex : index = 0;
arrfirst[index].disabled = false ;
arrfirst[index].disabled = false; // --> this will enable any disabled element.

arrfirst[index].disabled = true; // --> this will disable any enabled element.
Jun 5 '07 #2
arrfirst[index].disabled = false; // --> this will enable any disabled element.

arrfirst[index].disabled = true; // --> this will disable any enabled element.

Hi

but its not working.its giving error like "undefined".
arrfirst[index] is working but arrfirst[index].disabled is not working.
Jun 5 '07 #3
sumittyagi
202 Expert 100+
Hi

but its not working.its giving error like "undefined".
arrfirst[index] is working but arrfirst[index].disabled is not working.
It works fine dear!
there might be any other problem in your code.
Here is a typical example of disabling elements on a page.

Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3. <TITLE> New Document </TITLE>
  4. <script language="javascript" type="text/javascript">
  5. function disableElements(elemArr)
  6. {
  7.     for(var i=0; i<elemArr.length; i++)
  8.     {
  9.         elemArr[i].disabled = true;
  10.         var elemType = "";
  11.         var elemName = "";
  12.  
  13.         if(elemArr[i].nodeName == "INPUT")
  14.             elemType = elemArr[i].getAttribute("type");
  15.         else
  16.             elemType = elemArr[i].nodeName;
  17.  
  18.         if(elemArr[i].nodeName == "INPUT" || elemArr[i].nodeName == "SELECT" || elemArr[i].nodeName == "TEXTAREA")
  19.             elemName = elemArr[i].getAttribute("name");
  20.         else
  21.             elemName = elemArr[i].getAttribute("id");
  22.  
  23.         alert(elemType + " with name/id " + elemName + " is disabled.");
  24.     }
  25. }
  26.  
  27. function enableElements(elemArr)
  28. {
  29.     for(var i=0; i<elemArr.length; i++)
  30.     {
  31.         elemArr[i].disabled = false;
  32.         var elemType = "";
  33.         var elemName = "";
  34.  
  35.         if(elemArr[i].nodeName == "INPUT")
  36.             elemType = elemArr[i].getAttribute("type");
  37.         else
  38.             elemType = elemArr[i].nodeName;
  39.  
  40.         if(elemArr[i].nodeName == "INPUT" || elemArr[i].nodeName == "SELECT" || elemArr[i].nodeName == "TEXTAREA")
  41.             elemName = elemArr[i].getAttribute("name");
  42.         else
  43.             elemName = elemArr[i].getAttribute("id");
  44.  
  45.         alert(elemType + " with name/id " + elemName + " is enabled.");
  46.     }
  47. }
  48.  
  49. function enableDisableElemets(disableAll)
  50. {
  51.     var elemArr = new Array();
  52.     var frm = document.forms["edForm"];
  53.     elemArr[0] = document.getElementById("txt1");
  54.     elemArr[1] = frm.bttn1;
  55.     elemArr[2] = frm.radio1;
  56.     elemArr[3] = frm.chk1;
  57.     elemArr[4] = frm.txtArea1;
  58.     elemArr[5] = frm.select1;
  59.     elemArr[6] = document.getElementById("div1");
  60.  
  61.     if(disableAll)
  62.         disableElements(elemArr);
  63.     else
  64.         enableElements(elemArr);
  65. }
  66. </script>
  67. </HEAD>
  68.  
  69. <BODY>
  70. <form name="edForm">
  71. <input type="text" name="txt1" id="txt1" value="txt1">
  72. <input type="button" name="bttn1" value="bttn1">
  73. <input type="radio" name="radio1">
  74. <input type="checkbox" name="chk1">
  75. <textarea id="txtArea1" name="txtArea1">txtArea1</textarea>
  76. <select id="select1" name="select1">
  77. <option>opt1</option>
  78. <option>opt2</option>
  79. </select>
  80. <div id="div1">This is div1</div>
  81. <br><br>
  82. <input type="button" value="Enable Elements" onclick="enableDisableElemets(false)">
  83. <input type="button" value="Disable Elements" onclick="enableDisableElemets(true)">
  84. </form>
  85. </BODY>
  86. </HTML>
  87.  
Jun 5 '07 #4
Hi,

I am trying but still same problem is coming.please check this and give me a solution. here property means name. i cant give id for <html:text />

<select id="Types" name="Types[<%=index%>]" size="1" onChange="enableTypes('<%="Warning["+index+ "]"%>','<%="Critical[" + index + "]"%>','<%=index%>')">
<option value="First" >First</option>
<option value="Second" >Second</option> </select>

<html:text disabled="true" property='<%="Warning[" + index + "]"%>' size="8" maxlength="255" value="" />

<html:text disabled="true" property='<%="Critical[" + index + "]"%>' size="8" maxlength="255" value="" />
Jun 7 '07 #5
sumittyagi
202 Expert 100+
Hi,

I am trying but still same problem is coming.please check this and give me a solution. here property means name. i cant give id for <html:text />

<select id="Types" name="Types[<%=index%>]" size="1" onChange="enableTypes('<%="Warning["+index+ "]"%>','<%="Critical[" + index + "]"%>','<%=index%>')">
<option value="First" >First</option>
<option value="Second" >Second</option> </select>

<html:text disabled="true" property='<%="Warning[" + index + "]"%>' size="8" maxlength="255" value="" />

<html:text disabled="true" property='<%="Critical[" + index + "]"%>' size="8" maxlength="255" value="" />
I havn't worked on struts.
But form elements can be referenced by their name (through form's reference) either it is text or any input element.

access text by name rather than id in my code, it will work then too.
I am sure its not a javascript problem, there might be any other problem with your code. review your code thoroughly.

Note: whenever javascript shows this type of unexpected behaviour, it might be possible you might have used any reserved word of javascript in your code. Check all the names you have given to ur controls.
Jun 8 '07 #6
I havn't worked on struts.
But form elements can be referenced by their name (through form's reference) either it is text or any input element.

access text by name rather than id in my code, it will work then too.
I am sure its not a javascript problem, there might be any other problem with your code. review your code thoroughly.

Note: whenever javascript shows this type of unexpected behaviour, it might be possible you might have used any reserved word of javascript in your code. Check all the names you have given to ur controls.


thanks.
it is working fine.i am using hidden fields . i given the same name for textbox and hidden field.
Jun 12 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: KS | last post by:
Im trying to prevent the user from clicking any other links on my page when the user have selected/clicked a href once. Sometimes it takes a while before the next page loads so some user will try...
12
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
2
by: techfuzz | last post by:
I scoured this group and others looking for the best way to disable a button after the first click to prevent multiple submissions, but never did find anything that worked like they said it would. ...
2
by: bigrich | last post by:
I'm a beginner to javascript and need help. I've searched the forum but can't piece the answer together. I need to be able to uncheck and disable a checkbox based on the option selected in a...
1
by: s.chelliah | last post by:
Hi, I am trying to use javascript, div tag and radio button to disable/enable a text box. It works fine in netscape and firefox, but in IE, the text box is not disabled when the user checks the...
6
by: Mike | last post by:
I have a form that contains 240 "products". Each Product has a TR. Each TR contains a Yes and No radio button and a Product-Qty text input. A situation exists where I have to go through all the...
9
by: surf_doggie | last post by:
Im not sure if this is the group to post in, if anyone knows a more appropriate one please let me know. Please consider the following example of a feature most all browsers have that I would...
8
by: alamodgal | last post by:
hiiiiiiiiiii everybody, pls solve my problem if u can? Actualy what happens in my site when i press enter key it will show some secured...
3
by: Venturini | last post by:
I am trying to put together a web page where the customer makes choices of products and is then given a total. I am extremely new to Javascript and have managed to get as far as I have from web...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.