Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
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 July 18th, 2003, 08:44 AM
Authorized User
 
Join Date: Jun 2003
Location: Lexington, KY, USA.
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

Maybe I can help further if you post the relevant parts of your page (HTML and script).



-Van
(Old dog learning new tricks...)
 
Old July 24th, 2003, 02:46 AM
Authorized User
 
Join Date: Jun 2003
Location: Quezon City, NCR, Philippines.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to vickriz
Default

Quote:
quote:Originally posted by vknowles
 Maybe I can help further if you post the relevant parts of your page (HTML and script).
ok here it is the whole code..
Code:
Javascript:
function myChange(pT)
{
    switch(pT.value.toUpperCase())
    {
        case 'M':
        case 'R':
            document.getElementById('SpouseFN').disabled=false;
            document.getElementById('SpouseMN').disabled=false;
            document.getElementById('SpouseLN').disabled=false;
            document.getElementById('SpouseNS').disabled=false;
            break;
        case 'S':
            document.getElementById('SpouseFN').disabled=true;
            document.getElementById('SpouseMN').disabled=true;
            document.getElementById('SpouseLN').disabled=true;
            document.getElementById('SpouseNS').disabled=true;
            break;
        default:
            alert('Your input '+ ccForm.ccCivilStatus.value + ' is incorrect!');
            document.ccForm.ccCivilStatus.focus();
        break;
    }
}

HTML:
<FORM name="ccForm" method="post"> 
<TABLE>
  <tr>
    <td><span>G</span>ender</td>
    <td> 
      <input type="text" name="ccGender" id="Gender" accesskey="G" tabindex="8" maxlength="1" size="8" value="MALE" onChange="displayMe(this);" onMouseOver="window.status='Input should be M for Male and F for Female'; return true;" onMouseOut="window.status=''">M/F</td>
  </tr>
  <tr>
    <td>Ci<span>v</span>il Status</td>
    <td>
      <input type="text" name="ccCivilStatus" id="CivilStatus" accesskey="V" tabindex="9" maxlength="1" size="12"onChange="myChange(this);" onMouseOver="window.status='S=Single, M=Married, W=Widow, R=Separated'; return true;" onMouseOut="window.status=''">
    </td>
  </tr>
</TABLE>
</form>
Mabuhay!!!
 
Old July 24th, 2003, 08:26 AM
Authorized User
 
Join Date: Jun 2003
Location: Lexington, KY, USA.
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try the following version of your script.
The focus() method in the onChange event doesn't do anything because during the event the focus has not changed. Your user changes the focus later, after the event has completed.
But with the setTimeout method, you are delaying the snippet of code long enough that the onChange event completes, then the onFocus event fires.
Because the timed-out code fires in its own context, you have to use an independent reference to the text box (getElementById...).
I like to use the parameter value (pT) where possible. When referencing an element, I like to use the ID attribute, not the NAME attribute, because NAME is not unique. When I use both on an element, I always make sure they are the same (ID=NAME). Yours are not (CivilStatus != ccCivilStatus).

function myChange(pT)
{
    switch(pT.value.toUpperCase())
    {
        case 'M':
        case 'R':
            document.getElementById('SpouseFN').disabled=false ;
            document.getElementById('SpouseMN').disabled=false ;
            document.getElementById('SpouseLN').disabled=false ;
            document.getElementById('SpouseNS').disabled=false ;
            break;
        case 'S':
            document.getElementById('SpouseFN').disabled=true;
            document.getElementById('SpouseMN').disabled=true;
            document.getElementById('SpouseLN').disabled=true;
            document.getElementById('SpouseNS').disabled=true;
            break;
        default:
            alert('Your input '+ pT.value + ' is incorrect!');
            setTimeout('document.getElementById(\''+pT.id+'\') .focus()',10);
        break;
    }
}



-Van
(Old dog learning new tricks...)




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.