 |
| 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
|
|
|
|

June 25th, 2003, 04:36 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!!!
|
|

June 27th, 2003, 02:36 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.
|
|

June 30th, 2003, 04:26 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!!!
|
|

June 30th, 2003, 04:35 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!!!
|
|

June 30th, 2003, 08:22 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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...)
|
|

June 30th, 2003, 08:41 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!!!
|
|

July 1st, 2003, 09:13 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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...)
|
|

July 17th, 2003, 12:08 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!!!
|
|

July 17th, 2003, 08:55 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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...)
|
|

July 18th, 2003, 05:39 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!!!
|
|
 |