www.webdeveloper.com
Results 1 to 8 of 8

Thread: Newbie - Please help to code this simple form

  1. #1
    Join Date
    Jul 2008
    Posts
    5

    Newbie - Please help to code this simple form

    Hi guys, I am completely new to Java scripting and I would like to ask for your support on this form.
    My form is simple:
    - One text field, named as "T1" which will accept only numbers range from 0 to 50.
    - One checkbox, named as "C1". Initially will be invisible and unchecked.
    This checkbox C1 will only VISIBLE and CHECKED if user's input value in T1 is 0 (zero).

    I would prefer the verification is "on-the-fly" and happen before any form SUBMIT action.

    I think this is simple but I have spent almost a day and I got nothing.
    Can you guys help to code this?
    Thanks a ton.

  2. #2
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,755

  3. #3
    Join Date
    Jul 2008
    Posts
    5
    Hi,
    The problem is: I have the idea, but dunno how to code.
    Can you help to from the start? It would be a great help for me and i am really appreciate that.

  4. #4
    Join Date
    Jul 2008
    Posts
    5
    hi
    After a huge try and google, this is my code and it failed to work in DW CS2

    Can you guys have a look?

    ============

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>

    <script type="text/javascript">
    function Check()
    {
    var value = document.getElementById(Q23_C1).checked;

    var

    if (value == checked)
    {
    document.getElementById(Q23_T1).disabled=true;
    document.getElementById(Q23_T2).disabled=true;
    document.getElementById(Q23_T3).disabled=true;
    document.getElementById(Q23_T4).disabled=true;
    document.getElementById(Q23_T5).disabled=true;
    }
    else
    {
    document.getElementById(Q23_T1).disabled=false;
    document.getElementById(Q23_T2).disabled=false;
    document.getElementById(Q23_T3).disabled=false;
    document.getElementById(Q23_T4).disabled=false;
    document.getElementById(Q23_T5).disabled=false;
    }
    }
    </script>

    </head>

    <body>
    <p>
    <label>www.
    <input type="text" name="Q23_T1" id="Q23_T1" size="40" value="Type the site name here" onfocus = "javascript: if(this.value=='Type the site name here') {this.value='';}"*>
    </label>
    </p>
    <p>
    <label>www.
    <input type="text" name="Q23_T2" id="Q23_T2" size="40" value="Type the site name here" onfocus = "javascript: if(this.value=='Type the site name here') {this.value='';}"*>
    </label>
    </p>
    <p>
    <label>www.
    <input type="text" name="Q23_T3" id="Q23_T3" size="40" value="Type the site name here" onfocus = "javascript: if(this.value=='Type the site name here') {this.value='';}"*>
    </label>
    </p>
    <p>
    <label>www.
    <input type="text" name="Q23_T4" id="Q23_T4" size="40" value="Type the site name here" onfocus = "javascript: if(this.value=='Type the site name here') {this.value='';}"*>
    </label>
    </p>
    <p>
    <label>www.
    <input type="text" name="Q23_T5" id="Q23_T5" size="40" >
    </label>
    <p>

    <label>
    <input name="Q23_C1" type="checkbox" id="Q23_C1" onselect="Check()" >
    I do not use the internet for finding out about Vietnam
    </label>
    </p>


    </body>
    </html>

  5. #5
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,755

  6. #6
    Join Date
    Jul 2008
    Posts
    5
    Errr...
    Thanks, but now that junk has been removed.
    And I have tried with all events on the checkbox --> onclick, onchange, on.......
    but still it dis not work.
    Can you break that down and help me to fix it.

  7. #7
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,252

    Question More info please ...

    First, post your modified code. Let us see what you are working with.

    Second, what kind of errors are you getting? Error messages help a bunch when it comes to debugging.

    "but still it dis not work" does not help much.

  8. #8
    Join Date
    Jul 2008
    Posts
    5
    Hi guys,

    The modified code is below:

    WHen i load the page into IE, the "auto clear" script work well - the function Check() is not running. IE status bar says: "Error on page"

    I removed all the script associated with the textbox, but the Check() function is not running.

    I suspect the error is either in the following lines:

    var value = document.getElementById(Q23_C1).checked;

    if (value == true)

    ...and in the event handler

    <input name="Q23_C1" type="checkbox" id="Q23_C1" onclick="Check()" >
    I do not use the internet for finding out about Vietnam


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>

    <script type="text/javascript">
    function Check()
    {
    var value = document.getElementById(Q23_C1).checked;

    if (value == true)
    {
    document.getElementById(Q23_T1).disabled=true;
    document.getElementById(Q23_T2).disabled=true;
    document.getElementById(Q23_T3).disabled=true;
    document.getElementById(Q23_T4).disabled=true;
    document.getElementById(Q23_T5).disabled=true;
    }
    else
    {
    document.getElementById(Q23_T1).disabled=false;
    document.getElementById(Q23_T2).disabled=false;
    document.getElementById(Q23_T3).disabled=false;
    document.getElementById(Q23_T4).disabled=false;
    document.getElementById(Q23_T5).disabled=false;
    }
    }
    </script>

    </head>

    <body>
    <p>
    <label>www.
    <input type="text" name="Q23_T1" id="Q23_T1" size="40" value="Type the site name here" onfocus = "javascript: if(this.value=='Type the site name here') {this.value='';}"*>
    </label>
    </p>
    <p>
    <label>www.
    <input type="text" name="Q23_T2" id="Q23_T2" size="40" value="Type the site name here" onfocus = "javascript: if(this.value=='Type the site name here') {this.value='';}"*>
    </label>
    </p>
    <p>
    <label>www.
    <input type="text" name="Q23_T3" id="Q23_T3" size="40" value="Type the site name here" onfocus = "javascript: if(this.value=='Type the site name here') {this.value='';}"*>
    </label>
    </p>
    <p>
    <label>www.
    <input type="text" name="Q23_T4" id="Q23_T4" size="40" value="Type the site name here" onfocus = "javascript: if(this.value=='Type the site name here') {this.value='';}"*>
    </label>
    </p>
    <p>
    <label>www.
    <input type="text" name="Q23_T5" id="Q23_T5" size="40" >
    </label>
    <p>

    <label>
    <input name="Q23_C1" type="checkbox" id="Q23_C1" onclick="Check()" >
    I do not use the internet for finding out about Vietnam
    </label>
    </p>


    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles