HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 31st, 2004, 07:11 PM
Rabbit Rabbit is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 6 Rabbit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile Javascript to disable form field

Hi People,

I have made a simple ASP website. Need to add some spice to it.
I have a check box, a text box and a combo box. I want the text boxes to be disabled if the check box is checked.

I also want another text box to be disabled if a particular option in a combo box is selected.

Any suggestions?

What I have is this: How do I modify it?

wHEN TEXT IS ENTERED IN TEXT BOX 1, TEXT BOX 2 IS DISABLED. FEATURES COLOR CHANGE
--------------------------------------------------------------------------------------

<form name="form">
<input type="text" name="text1" onkeyup="this.form.text2.disabled=true;this.form.text2.styl e.background='#E8E8E8'" /><br><br>
<input type="text" name="text2" onkeyup="this.form.text1.disabled=true;this.form.text1.styl e.background='#E8E8E8'" />
</form>

Thanks

Last edited by Lafinboy : October 31st, 2004 at 07:26 PM. Reason: Corrected title

Reply With Quote
  #2  
Old November 1st, 2004, 01:43 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,969 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 15 h 9 m 16 sec
Reputation Power: 1556
we can't do all the work for you. look in the code, learn it, understand how it works and then you will be able to write your own code. that's the goal of my help here. not feeding with silver spoon.

Reply With Quote
  #3  
Old November 1st, 2004, 12:28 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 21 h 32 m 23 sec
Reputation Power: 180
If you need to look something up you can check here

http://msdn.microsoft.com/workshop/author/dhtml/dhtml_node_entry.asp
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #4  
Old November 1st, 2004, 08:16 PM
Rabbit Rabbit is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 6 Rabbit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi people,


Thanks a lot for your replies. I am sorry shadow if u felt i was trying to get a free lunch, but trust me, that was not my intention. Thanks to you too doug, your link was very helpful.

This is what I got now:

function checkstatus ()
{
if S10C1.checked = true -----(S10C1 is the name of the checkbox)
{
" this.form.S10T8.disabled = true"; -----------(S10T8 is the name of the text box )
}
}

Input type = checkbox name= S10C1 value = Mainframe
----- other code-----

This does not seem to work. When i paste the line of code in that function directly where my checkbox is defined ( for instance input type = checkbox name = S10C1 value = mainframe onclick= "whatever i want to happen..." it works, but when i uncheck the checkbox, the textbox is not enabled again.

Thanks again,

Rabbit

Reply With Quote
  #5  
Old November 1st, 2004, 08:50 PM
Lafinboy's Avatar
Lafinboy Lafinboy is offline
The Laughing Moderator
ASP Free Loyal (3000 - 3499 posts)
 
Join Date: Apr 2004
Location: Sydney, Australia
Posts: 3,263 Lafinboy User rank is Sergeant (500 - 2000 Reputation Level)Lafinboy User rank is Sergeant (500 - 2000 Reputation Level)Lafinboy User rank is Sergeant (500 - 2000 Reputation Level)Lafinboy User rank is Sergeant (500 - 2000 Reputation Level)Lafinboy User rank is Sergeant (500 - 2000 Reputation Level)  Folding Points: 29199 Folding Title: Starter FolderFolding Points: 29199 Folding Title: Starter Folder
Time spent in forums: 2 Weeks 1 Day 10 h 35 m 51 sec
Reputation Power: 15
Send a message via ICQ to Lafinboy Send a message via AIM to Lafinboy Send a message via MSN to Lafinboy Send a message via Yahoo to Lafinboy Send a message via Skype to Lafinboy
Try something more like this:
Code:
<input type="checkbox" name="checkbox1" id="chk" onChange="chkCheck();" value="ON" /><br />
<script language="javascript" type="text/javascript">
function chkCheck()
{
if (document.form1.checkbox1.checked)
{
document.form1.text.value=''; // clear the contents of the field
document.form1.text.disabled=true; // disable the field
}
else
{
document.form1.text.disabled=false; // change back to enabled
}
}
</script>


I'm no guru when it comes to JS, so I guess it could be optimised, but it does what you're after.

Reply With Quote
  #6  
Old November 1st, 2004, 08:59 PM
nschafer's Avatar
nschafer nschafer is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Mar 2004
Location: Florida
Posts: 584 nschafer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 46 m 5 sec
Reputation Power: 5
Lafinboy is on the right track, but if you actually want to hide the text boxes, change the code he posted slightly.


Code:
<input type="checkbox" name="checkbox1" id="chk" onChange="chkCheck();" value="ON" /><br />
<script language="javascript" type="text/javascript">
function chkCheck()
{
if (document.form1.checkbox1.checked)
{
document.form1.text.value=''; // clear the contents of the field
document.form1.text.style.visibility='hidden';  // hide the field
}
else
{
document.form1.text.style.visibility='visible'; // change back to visible
}
}
</script>


You can do the same thing for the combo box based on selection criteria.

Hope this helps,
__________________
Neal Schafer
The early worm gets eaten.

Reply With Quote
  #7  
Old November 2nd, 2004, 11:28 AM
jbruso jbruso is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 279 jbruso User rank is Lance Corporal (50 - 100 Reputation Level)jbruso User rank is Lance Corporal (50 - 100 Reputation Level)jbruso User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Days 17 h 31 m 46 sec
Reputation Power: 5
Send a message via AIM to jbruso Send a message via MSN to jbruso Send a message via Yahoo to jbruso
Neal,

i think your code can help me with what I am trying to do.

What other options are available with the .style.visibility='hidden'
property? can I use style.??? to change the border color around a form field? So, instead of hiding the field, I color it or highlight it with a background color or bordercolor...then this becomes a validation tool?

Thanks for your help,

John

Reply With Quote
  #8  
Old November 2nd, 2004, 11:38 AM
nschafer's Avatar
nschafer nschafer is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Mar 2004
Location: Florida
Posts: 584 nschafer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 46 m 5 sec
Reputation Power: 5
You can set any available style setting for the object. Be aware that not all browsers treat styles the same way so you may have to do some browser dependent settings to ensure that all users see what you are trying to display. An example of this is that in some browsers visibility: collapse; for a table row will not only hide the information on the row, but make the row disappear as well. In other browsers this does not work and you use display:none; instead.

The following site has some good general information on CSS as well as a number of browser specific suggestions.

http://www.htmlhelp.com/reference/css/references.html

Hope this helps,

Reply With Quote
  #9  
Old November 2nd, 2004, 12:01 PM
selwonk's Avatar
selwonk selwonk is offline
Contributing User
ASP Free Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2004
Posts: 2,942 selwonk User rank is Second Lieutenant (5000 - 10000 Reputation Level)selwonk User rank is Second Lieutenant (5000 - 10000 Reputation Level)selwonk User rank is Second Lieutenant (5000 - 10000 Reputation Level)selwonk User rank is Second Lieutenant (5000 - 10000 Reputation Level)selwonk User rank is Second Lieutenant (5000 - 10000 Reputation Level)selwonk User rank is Second Lieutenant (5000 - 10000 Reputation Level)selwonk User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 6 Days 9 h 49 m 28 sec
Reputation Power: 62
Would you mind if I moved this post to the HTML Help forum? It has much more relevance there
__________________
selwonk

If I've posted some code above, you might think it looks a bit simplistic. It might be. I'd rather people tried the next step themselves rather than getting a full solution on a plate. That way they learn more!

Reply With Quote
  #10  
Old November 2nd, 2004, 12:22 PM
jbruso jbruso is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 279 jbruso User rank is Lance Corporal (50 - 100 Reputation Level)jbruso User rank is Lance Corporal (50 - 100 Reputation Level)jbruso User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Days 17 h 31 m 46 sec
Reputation Power: 5
Send a message via AIM to jbruso Send a message via MSN to jbruso Send a message via Yahoo to jbruso
nope, go ahead...

although I'm still struggling.... Soooo close too.... I have the script validating the form, alerting the user and even replacing the field class... but its only doing it to one field! Argghhhhhh

a little help? Please, with cherrys on top?

Code:
<style type="text/css">
<!--
.field {
border: thin dashed #FF0000;
color: #990000;
background-color: #FFCCFF;
}
-->
</style>

Code:
 <script language="JavaScript">
function change(id, newClass) {
identity=document.getElementById(id);
identity.className=newClass;
}
</script>
<script>
function validateForm() {
with (document.myform) {
var alertMsg = "The following REQUIRED fields\nhave been left empty:\n";
if (h.value == "") alertMsg += "\nYour First Name"; 
if (j.value == "") alertMsg += "\nYour Last Name";
if (alertMsg != "The following REQUIRED fields\nhave been left empty:\n") {
alert(alertMsg);
change('changeme','field');
return false;
} else {
return true;
} 
} }
</script>


Code:
 <TABLE>
<TR>
	<TD align="right">First:</TD>
	<TD><input name="h" type="text" size="17" id="changeme"></TD>
</TR>
<TR>
	<TD align="right">Middle:</TD>
	<TD><input name="i" type="text" size="17" id="changeme2"></TD>
</TR>
   <TR>
	<TD align="right">Last:</TD>
	<TD><input name="j" type="text" size="17" id="changeme3"></TD>
   </TR>
</TABLE> 

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Javascript to disable form field


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway