Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 25th, 2003, 04:36 AM
Authorized User
 
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to vickriz
Default Enable form_textbox when input = M or R??

Hi to all.
i have a little problem need to ask.
in my form[myform] i have inputbox civilStatus. if the user enter either M[married] or R[separated] the next four textfield[spouseLN, spouseFN, spouseSN, spouseNick] will enabled. if the user enter S the spouse field will stay as readonly.
how this behaviour can attained in javascript??

Note: the textfield spouse are readonly by default..

pls help....



Mabuhay!!!
__________________
Mabuhay!!!
 
Old June 27th, 2003, 02:36 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can use an onFocus event on the text box, and if it gets focus check the value of the other field, if it is one value, then allow them to enter data into the field, otherwise blur the field. You could also do this the other way around with the selection of the type triggering the event to change the readonly status.
 
Old June 30th, 2003, 04:26 AM
Authorized User
 
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to vickriz
Default

hi there again..

i get your idea but i dont know where to start the script..

can u help me out??

thanks in advance..

Mabuhay!!!
 
Old June 30th, 2003, 04:35 AM
Authorized User
 
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to vickriz
Default

Quote:
quote:Originally posted by Greg Griffiths
 You can use an onFocus event on the text box, and if it gets focus check the value of the other field, if it is one value, then allow them to enter data into the field, otherwise blur the field. You could also do this the other way around with the selection of the type triggering the event to change the readonly status.
can u show my a working sample codes??





Mabuhay!!!
 
Old June 30th, 2003, 08:22 AM
Authorized User
 
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

The onfocus event should work, but I think it would be more user-friendly to use the onchange event of the civilStatus text box:

<INPUT TYPE=TEXT ID=civilStatus onChange="myChange(this);"...>
...
<SCRIPT ...>
function myChange(pT)
{
switch(pT.value.toUpperCase())
{
case 'M':
case 'R':
document.getElementById('spouseLN').disabled=true;
//repeat for each spouse field
break;
default:
document.getElementById('spouseLN').disabled=false ;
//repeat for each spouse field
break;
}
}
</SCRIPT>

I use toUpperCase() because I don't know if your user can enter upper and lower case letters.

You can also use the switch to do validation in the same place. So, you could put "case 'S':" where the "default:" statement is, and change the "default:" code to issue an alert that it is not a valid entry.

-Van


-Van
(Old dog learning new tricks...)
 
Old June 30th, 2003, 08:41 PM
Authorized User
 
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to vickriz
Default

Quote:
quote:You can also use the switch to do validation in the same place. So, you could put "case 'S':" where the "default:" statement is, and change the "default:" code to issue an alert that it is not a valid entry.
hi again van...

i did something like what u said with alert and it works. now how about if after the alert i still want to stay the cursor focus on my civilStatus field?? what should be the code?

thanks again..

Mabuhay!!!
 
Old July 1st, 2003, 09:13 AM
Authorized User
 
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

Okay, this should work, after your alert(...) statement:

pT.focus();

where pT is the reference to your civilStatus text box. In my example code, it was passed as a parameter "pT".

-Van

-Van
(Old dog learning new tricks...)
 
Old July 17th, 2003, 12:08 AM
Authorized User
 
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to vickriz
Default

Quote:
quote:Originally posted by vknowles
 Okay, this should work, after your alert(...) statement:

pT.focus();

where pT is the reference to your civilStatus text box. In my example code, it was passed as a parameter "pT".

-Van

-Van
(Old dog learning new tricks...)
pT.focus(); = it didnt work..
i put this code after
Code:
...
alert('...');
pT.focus();
break;
...


Mabuhay!!!
 
Old July 17th, 2003, 08:55 AM
Authorized User
 
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

I'm not sure why it would not work. Maybe there's a problem using the focus() method inside the onchange event. You might try using the onBlur event instead, but your code would then run every time someone tabs or mouses out of the text box, even if they did not make a change.

What [u]did</u> it do, exactly? Did it cause a javascript error, or just not do anything, or what?


-Van
(Old dog learning new tricks...)
 
Old July 18th, 2003, 05:39 AM
Authorized User
 
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to vickriz
Default

Quote:
quote:Originally posted by vknowles
What [u]did</u> it do, exactly? Did it cause a javascript error, or just not do anything, or what?


-Van
(Old dog learning new tricks...)
it does not do anything at all after the changing made and then alert..

Mabuhay!!!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Enable Property kekec3778 Beginning VB 6 2 January 8th, 2008 06:32 AM
Enable Update and Enable Delete check boxes don't mihabib ASP.NET 2.0 Basics 2 December 7th, 2006 11:44 AM
Enable - Macros alannoble26 Excel VBA 2 November 28th, 2005 09:08 AM
Enable Assertions ssmith71 BOOK: Beginning Java 2, JDK 5 Edition 0 June 3rd, 2005 12:03 PM
Failed to enable constraints ysu_computer_lab VS.NET 2002/2003 1 November 4th, 2003 11:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.