Results 1 to 9 of 9

Thread: [RESOLVED] Javasript Syntex Error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    204

    Resolved [RESOLVED] Javasript Syntex Error

    I am not sure why keep getting syntax error on the high lighted line of code. pls help "code hint may not work until you fix error"
    Code:
    <sript>
    window.onload = function() {
    document.getElementById('checkstatus_0').onchange = disablefield;document.getElementById('checkstatus_1').onchange = disablefield;
    }

  2. #2
    Hyperactive Member coothead's Avatar
    Join Date
    Oct 2007
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    284

    Re: Javasript Syntex Error

    Hi there alobi,

    just giving us the line where the error occurs is not enough to pinpoint the cause of the problem.

    Please supply a link to site in question or failing that enough of the page code to locate the fault.

    As it stands, you do have a spelling error or typo: sript should be script.


    ~ the original bald headed old fart ~

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    204

    Re: Javascript Syntex Error

    I am sorry for the omission

    Code:
    script
    window.onload = function() {
    document.getElementById('phone_no').onchange = disablefield;
    document.getElementById('phone_yes').onchange = disablefield;
    }
    
    function disablefield()
    {
    if ( document.getElementById('phone_no').checked == true ){
    document.getElementById('PhoneNumber').value = '';
    document.getElementById('PhoneNumber').disabled = true}
    else if (document.getElementById('phone_yes').checked == true ){
    document.getElementById('PhoneNumber').disabled = false;}
    }
    
    </script>

  4. #4
    Hyperactive Member coothead's Avatar
    Join Date
    Oct 2007
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    284

    Re: Javascript Syntex Error

    Hi there alobi

    do the "phone_no" and "phone_yes" refer to <input type="checkbox"> elements?


    ~ the original bald headed old fart ~

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    204

    Re: Javasript Syntex Error

    Good, Morning,
    I may have posted an old code, please forgive me. I am sorry, here is the corrected code and I am still having the same issue. Also
    I notice another problem. The code is not doing what I expected and I do not think it is related to the syntax error.

    I want to be able to disable the phone number textbox when the lastname option button is clicked, and disable the lastname textbox when the option button for phone number is clicked. The aim is to make sure that users do not enter information in both textboxes at the same time.
    Thank you for your time
    HTML Code:
    <html>
    <head>
    <title>Disable</title>
    <script>
    window.onload = function() {
    document.getElementById('phone').onchange = disablefield;
    document.getElementById('name').onchange = disablefield;
    document.getElementById('LastName').disabled = false;
    document.getElementById('PhoneNumber').disabled = false;
    document.getElementById('name').checked = false;
    document.getElementById('phone').checked = false;
    }
    
    function disablefield()
    {
    if ( document.getElementById('name').checked == true ){
    document.getElementById('PhoneNumber').value = '';
    document.getElementById('PhoneNumber').disabled = true;
    document.getElementById('LastName').disabled = false;}
    else if (document.getElementById('phone').checked == true ){
    document.getElementById('LastName').value = '';
    document.getElementById('LastName').disabled = true;
    document.getElementById('PhoneNumber').disabled = false;}
    }
    </script>
    </head>
    
    <body>
    
    <form action="#" method="get" name="admin">
    Phone: <input type="radio" name="idmethod" value="phone" id="phone"/>
    <input name="PhoneNumber" type="tel" id="PhoneNumber" size="25" />
    <br/><br/>
    Name:<input type="radio" name="idmethod" value="name" id="name"/>
    <input name="LastName" type="text" id="LastName" size="25" />
    </form>
    </body>
    </html>

  6. #6
    Hyperactive Member coothead's Avatar
    Join Date
    Oct 2007
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    284

    Re: Javasript Syntex Error

    Hi there alobi,

    unfortunately, I have to go out for two or three hours.

    I will get a reply to you, hopefully, by 6:00pm G.M.T.


    ~ the original bald headed old fart ~

  7. #7
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Javasript Syntex Error

    The code is not doing what I expected and I do not think it is related to the syntax error.
    It most certainly is related... it's not doing what you expect because the script is "broken" and so it can't run....

    however... it seems to almost work jsut fine for me... I don't get any syntax errors... and when I click one option button the other text box clears out... tried it in IE, and Firefox...

    I did notice a little bit of odd behaviour in IE though, after clicking the option button, it wouldn't clear out the old value until I clicked into the new textbox or somewhere else... so I question the OnChange event... if maybe there's a better event that should be handled.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    204

    Re: Javasript Syntex Error

    I created a new page, copied and pasted the same code on the page, it works fine. Thanks

  9. #9
    Registered User
    Join Date
    Jul 2013
    Posts
    1

    Re: [RESOLVED] Javasript Syntex Error

    yeah you be type <script> not like <sript>.this is wrong one.and i agreed with coothead.this is one example for you used to display the current date.
    <script>
    function displayDate()
    {
    document.getElementById("demo").innerHTML=Date();
    }
    </script>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width