473,387 Members | 1,742 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,387 software developers and data experts.

how can I disable and enable input type?

idsanjeev
241 100+
Hi
its urgent
how can enable and desable the input field with condition like
if rs("field")=1 then
desable
elseif re("field")=2 then
enable
end if
and that after chek if the input type is enable then manadatory field can't null
thanks
Jan 12 '08 #1
33 3490
acoder
16,027 Expert Mod 8TB
With JavaScript, you'd use the disabled property. However, if you're going to set it whilst the page is loading with ASP, just include it within the tag:
Expand|Select|Wrap|Line Numbers
  1. <input type="text" <% if it should be disabled, just print out: disabled="true" %> ...>
Re. the validation, please provide more details.
Jan 12 '08 #2
kunal pawar
297 100+
Hi..
u can used directly in page
like
[HTML]<input type='control- text/button etc' name='' id='' <%if rs("field")=1 then%>
disabled=true <%elseif re("field")=2 then%>disabled=false<%end if%>>[/HTML]
Jan 14 '08 #3
idsanjeev
241 100+
hi
I wants to use it in asp with vbscripts
and my need is to if selected option is floopy and cd then purpose Input filed is enable(show) ohterwiese purpose input field is(hide)
Thanks
Jan 16 '08 #4
gits
5,390 Expert Mod 4TB
hi ...

i'm not familiar with vb-script but in case you want to set the disabled-attribute dynamically then use something like this (javascript):

Expand|Select|Wrap|Line Numbers
  1. var input_node = document.getElementById('your_input_node_id');
  2.  
  3. // to disable the box
  4. input_node.setAttribute('disabled', 'disabled');
  5.  
  6. // to make it readonly (text stays selectable)
  7. input_node.setAttribute('readonly', 'readonly');
  8.  
  9. // to enable it simply remove the attributes
  10. input_node.removeAttribute('disabled');
  11.  
  12. // or 
  13. input_node.removeAttribute('readonly');
  14.  
kind regards
Jan 16 '08 #5
idsanjeev
241 100+
hello
where i have to use it can you sugest any position of code .
code would write within javascript tag
Jan 16 '08 #6
gits
5,390 Expert Mod 4TB
hi ...

you have to assign an eventhandler to your select-element and call a function:

[HTML]<select name="my_name" onchange="toggle_state(this);">[/HTML]
now in the head of your page define the script-node:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     function toggle_state(obj) {
  3.         // here we check the value of your select-box
  4.         var val = obj.value == 'floppy_cd';
  5.  
  6.         var input_node = document.getElementById('your_input_node_id');
  7.  
  8.         if (val) {
  9.             input_node.setAttribute('readonly', 'readonly');
  10.         } else {
  11.             input_node.removeAttribute('readonly');
  12.         }
  13.     }
  14. </script>
  15.  
kind regards
Jan 16 '08 #7
idsanjeev
241 100+
Hello
My need is if option value is slected cd or floopy then show input filed if option selected is cartidge then hide input filed but when the above code is used no any chnges in forms so please help me in this
Jan 16 '08 #8
gits
5,390 Expert Mod 4TB
you have to adapt the val-check to your option values of course.

are you sure that there are no changes? :) ... try to input something in case it should have been readonly ...

and please now tell clearly: should it be disabled, readonly or hidden?

kind regards

ps: please post your option html-code
Jan 16 '08 #9
idsanjeev
241 100+
Hi sorry
I think i can't give you crrect need or little mistak
ok i am trying to decribe in brif
i have a form that has option select from table and click on add for requition of material that is in loop
my need is if select option is cd or floppy then automatic show input field for input purpose and if option is selected cartidge then hide input field and the requestion is submitted one by one in loop i can't able to do this.there are three field in select option cd,floppy and cartidge
code for select option
Expand|Select|Wrap|Line Numbers
  1.      <option Selected Value>Select Item</option>
  2. <%
  3. Set RSITEM = CON.EXECUTE("SELECT * FROM CONSUM_ITEMS ORDER BY Item_code")
  4. %>
  5. <%
  6. Do While Not RSITEM.EOF
  7. %>        <option Value="<%=RSITEM("Item_code")%>"><%=RSITEM("Item_desc")%></option>
  8. <%
  9.  
  10. RSITEM.MoveNext
  11. Loop
  12.  
thanks
Jan 16 '08 #10
gits
5,390 Expert Mod 4TB
then we have to do some adaptions, here are the step-by-step hints:

1. give your input node an id and change the function accordingly ... so replace 'your_input_node_id' with your id

2. add the onchange-attribute the way i showed you

3. watch the magic ;)

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     function toggle_state(obj) {
  3.         // here we check the value of your select-box
  4.         var val = obj.value == 'cartridge';
  5.  
  6.         var input_node = document.getElementById('your_input_node_id');
  7.  
  8.         input_node.style.visibility = val ? 'hidden' : 'visible';
  9.     }
  10. </script>
  11.  
kind regards
Jan 16 '08 #11
idsanjeev
241 100+
Expand|Select|Wrap|Line Numbers
  1.  
  2. <b>Purpose( In case of CD/FLOPPY )</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  3.   <input type="text" name="purpose" id="purpose"  style="width:400px" maxlength="150"></td></tr>
  4.  
Expand|Select|Wrap|Line Numbers
  1.    <script language="javascript">
  2.   function toggle_state(obj) {
  3.         // here we check the value of your select-box
  4.         if var val = obj.value == 'cartridge'; 
  5.  
  6.         var input_node = document.getElementById('purpose');
  7.  
  8.         input_node.style.visibility = val ? 'hidden' : 'visible';
  9.     }
  10.  
  11.   </script>
  12.  
i chnges it like this is the incorrect if not then no magic
Jan 16 '08 #12
gits
5,390 Expert Mod 4TB
did you add the onchange:

[HTML]<select name="my_name" onchange="toggle_state(this);">[/HTML]
to your select-box too?

kind regards
Jan 16 '08 #13
idsanjeev
241 100+
hi
ya use this
[HTML]<option Value="<%=RSITEM("Item_code")%>" onchange="toggle_state(this);"><%=RSITEM("Item_des c")%></option>[/HTML]
Jan 16 '08 #14
gits
5,390 Expert Mod 4TB
hi ...

there is an error here, i overlooked it the first time, sorry, your adaption has the following error:

Expand|Select|Wrap|Line Numbers
  1. if var val = obj.value == 'cartridge';
you don't need the if here ;)

kind regards
Jan 16 '08 #15
idsanjeev
241 100+
hi
very fun today i am confuse how can solve it
my code is very long there are 286 line if you have some time then i send you my full code i there is any problems or i don't use the code provided in properway so please all works i don't know javascript
Jan 16 '08 #16
gits
5,390 Expert Mod 4TB
Expand|Select|Wrap|Line Numbers
  1.  
  2. <b>Purpose( In case of CD/FLOPPY )</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  3.   <input type="text" name="purpose" id="purpose"  style="width:400px" maxlength="150"></td></tr>
  4.  
Expand|Select|Wrap|Line Numbers
  1.    <script language="javascript">
  2.   function toggle_state(obj) {
  3.         // here we check the value of your select-box
  4.         if var val = obj.value == 'cartridge'; 
  5.  
  6.         var input_node = document.getElementById('purpose');
  7.  
  8.         input_node.style.visibility = val ? 'hidden' : 'visible';
  9.     }
  10.  
  11.   </script>
  12.  
i chnges it like this is the incorrect if not then no magic
have a look at the line 4 ... you added an if here ... that is useless, so simply remove it and it should work ...

sending the code is not a good idea, may be you have a link to a testpage?

kind regards
Jan 16 '08 #17
idsanjeev
241 100+
Hi Gits
I know that
but here is know file attachment option i am only online 1/2 hour tomorrow from morning 8 am ok
one more page but i send you only first page where first work is done
thanks
Jan 16 '08 #18
gits
5,390 Expert Mod 4TB
hi ...

in your code you have:

Expand|Select|Wrap|Line Numbers
  1.       <td Width="15%"><select Id="SEL_ITEM" Name="SEL_ITEM" Size="1">
  2.         <option Selected Value>Select Item</option>
  3. <%
  4. Set RSITEM = CON.EXECUTE("SELECT * FROM CONSUM_ITEMS ORDER BY Item_code")
  5. %>
  6. <%
  7. Do While Not RSITEM.EOF
  8. %>        <option Value="<%=RSITEM("Item_code")%>" onchange="toggle_state(this);"><%=RSITEM("Item_desc")%></option>
  9.  
change in a way that the onchange is added to the select-element like:

Expand|Select|Wrap|Line Numbers
  1. <select Id="SEL_ITEM" Name="SEL_ITEM" Size="1" onchange="toggle_state(this);">
  2.  
the onchange mustn't be added to the option-element

kind regards
Jan 16 '08 #19
idsanjeev
241 100+
hi ...

I Used your code but it not work when select option is selected automatic show input field and hide input field based on option
Jan 17 '08 #20
gits
5,390 Expert Mod 4TB
please explain in detail how the option will get automatically selected? ... in case you do it serverside you have to set the visibility of the input-box accordingly ...

kind regards
Jan 17 '08 #21
idsanjeev
241 100+
hi gits
i don't know about server side and client side
the main things wants to do when user login then a page is open with option to select item, quantity and submit to create requision for item he can add more then one item in same requision to add one by one so when he selected cd and floppy then show the input field if option is cartidge then hide show i don't know which type of code have to write client side or server side.
Jan 17 '08 #22
gits
5,390 Expert Mod 4TB
hi ...

please load your page to a browser and view the source-code -> copy that source-code from the browser, save it as a txt-file and post it here or send me a pm with it ... i have to have a closer look at it ...

kind regards
Jan 17 '08 #23
idsanjeev
241 100+
Hi Gits
Thanks for kind supports i attached here both page where these work is need
Jan 17 '08 #24
gits
5,390 Expert Mod 4TB
hi ...

you posted the asp-code ... but i wanted to have a look at the page when it is loaded to the browser :) ...

let me give you a working example here that uses the code:

[HTML]<html>
<script type="text/javascript">
function toggle_state(obj) {
// here we check the value of your select-box
var val = obj.value == 'cartridge';

var input_node = document.getElementById('purpose');

input_node.style.visibility = val ? 'hidden' : 'visible';
}
</script>
<body>
<select onchange="toggle_state(this);">
<option selected="selected" value="">select something</option>
<option value="cartridge">cartridge</option>
<option value="CD">CD</option>
<option value="floppy">floppy</option>
</select>
<input type="text" id="purpose" style="visibility:hidden;"/>
</body>
</html>
[/HTML]
have a look at it ... the onchange HAS to be added to the select and HASN'T to be added to the option (like in formsan1.txt) ... as far as i could see you preselect an option with no value ... so we could adapt the function then ... and have a look at the input-field ... i hide it initially ... now when you change the selected value we get the input shown in all cases except cartridge ...

kind regards
Jan 17 '08 #25
idsanjeev
241 100+
hi gits
sorry i have only these two page and one another that is submit requistion and generate report for requestion some other pages thats is departmentwise reports i know that i used it when another page it work fine but in these pages it not work why i don't know so what i have to do
thanks
Jan 17 '08 #26
idsanjeev
241 100+
Thanks Gits
You are the good guide i find it after long discussion with u
and i am very upsate becouse some confussion in the page that was not develped by me but i have to given this work for midification in the requestion system for restriction .
please if you have time then i know little about server side code and client side code by You. you are best gui.
thanks again
Jan 17 '08 #27
gits
5,390 Expert Mod 4TB
no problem ... glad to hear you got it working :) ... if you have more questions concerning client- and serverside coding please post a new thread to the forum ...

kind regards
Jan 17 '08 #28
idsanjeev
241 100+
Hi gits
you know whats is the problems where we are dusscused last time problems is select option is number and i am compairing it with character so this is the region of our long descussion realy i am mad.
sorry again problems in show and hide
problems is when first choosen by user is cartidge and any thing it work fine but addition for next item it not work.and when add button goes to error your case is cd and floppy so please enter purpose that message is report in case of cd and floppy after this message it work again
on the status bar it show error massage and double click on it show detail the error on line 25 object required char=5 code=0
Jan 18 '08 #29
gits
5,390 Expert Mod 4TB
the add-action submits the form ... is the page reloaded then? ... now i think i would really need a link to a testpage for futher assistence ... i need to see the data-flow and interactions etc. for my own ...

kind regards
Jan 18 '08 #30
idsanjeev
241 100+
Hi gits
i send a new file attachment thats work fine but don't work when the hidden property is one time added in requistion other wise its work fine
the error thats displayed in status bar that is object require in javasript where function toggle_state is diclare and compare with one .
Jan 18 '08 #31
gits
5,390 Expert Mod 4TB
hi ...

in your attached code you have:

Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="purpose" style="visibility:hidden; width:400px" maxlength="150" value=<%=porpose%>>
add an id-attribute since the toggle-function relies on it ...

kind regards
Jan 18 '08 #32
idsanjeev
241 100+
Hi gits
Thanks for your kind time to time guidance
this code work fine

Expand|Select|Wrap|Line Numbers
  1. function toggle_state(obj) {
  2.     // here we check the value of your select-box
  3.    //var val = obj.value == 1; 
  4.  
  5.     if (obj.value == 1)
  6.  {
  7.  val=1;
  8.  }
  9.  else
  10.  {
  11.  val=0;
  12.  }
  13.  
  14.     var input_node = document.getElementById('purpose');
  15.  
  16.     input_node.style.visibility = val ? 'hidden' : 'visible';
  17.  
  18. }
  19. </script>
Jan 19 '08 #33
gits
5,390 Expert Mod 4TB
Hi gits
Thanks for your kind time to time guidance
this code work fine

Expand|Select|Wrap|Line Numbers
  1. function toggle_state(obj) {
  2.     // here we check the value of your select-box
  3.    //var val = obj.value == 1; 
  4.  
  5.     if (obj.value == 1)
  6.  {
  7.  val=1;
  8.  }
  9.  else
  10.  {
  11.  val=0;
  12.  }
  13.  
  14.     var input_node = document.getElementById('purpose');
  15.  
  16.     input_node.style.visibility = val ? 'hidden' : 'visible';
  17.  
  18. }
  19. </script>
your adaption is definitly equivalent to the simple one line that you have 'outcommented' ... this couldn't have made a problem ... simply produces more lines of code and worse performance since 0 and 1 has to evaled to false/true in our assignment later on ... so it has to work with the

Expand|Select|Wrap|Line Numbers
  1. var val = obj.value == 1; 
  2.  
too?

kind regards
Jan 19 '08 #34

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

Similar topics

2
by: HolaGoogle | last post by:
Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have to field.One is a "yes/no" field and another one is "number" field. To display the yes/no field...
2
by: HolaGoogle | last post by:
Can you please tell me the right way to do this?? it's realy important! thanks in advance... Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have...
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>
1
by: Manatee | last post by:
Hi group. I have exactly one external, alternate stylesheet that I want to enable or disable by form controls, on one page only (not saved across pages). I used: <link rel="alternate...
1
by: hortoristic | last post by:
We are using JavaScript to Enable/Disable certain fields on web pages based on business rules. A simple example is if when using an option type tag, and the two options are Yes and No. If YES...
2
by: Kevin | last post by:
I've been looking all over and I can't seem to find what ought to be simple. I need to disable a drop down when a checkbox is checked, and enable it when same checkbox is unchecked. I've...
5
by: metalwing12 | last post by:
Hi guys can someone kindly help me about my code it seems incomplete or i just can make it right .I try using the disabled property of the textbox yes it workss, it disable it but when i set it...
10
by: viki1967 | last post by:
Disable/enable icon.gif Hi all. I have this form in the page.htm: <form action="form.asp" method="post" onsubmit="return(validateForm(this));"> <select size="1" name="t_im"...
10
by: sowmyati | last post by:
HI All, I am new to javascript. I have snippet wherein i am giving a brief note on what i am trying to do. In the below have a variable by name stuff. trying to reset the page. Part of the code...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.