www.webdeveloper.com
Results 1 to 5 of 5

Thread: OnChange is not working

  1. #1
    Join Date
    Nov 2012
    Posts
    5

    OnChange is not working

    Hello everyone:

    I have this problem:
    I need to check progamatically a Checkbox named 'comp' only when an input text field named 'cant' receives something.
    Here is my code, it is not working at all.

    $stream .= "<td><input type='text' name='cant' id='cant' size='5' onChange='document.form1.comp.checked=true' /></td>";
    $stream .= "<td><input type='checkbox' name='comp' value=$i /></td>";

    this code is within a form named 'form1'

    Any help is welcome.
    Thanks in advance.

  2. #2
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    903
    Your code actually works, but I'm assuming not like you want it to. For text inputs, the onchange event fires after the text box loses focus. If you are wanting to check the 'comp' box as keys are being pressed you may want to use onkeypress, onkeyup or onkeydown.

    Also, assuming you only want this box checked if there is actually text in your text box you may want to set up a function instead that checks the value of your 'cant' text box first before checking (or unchecking) the checkbox.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  3. #3
    Join Date
    Nov 2012
    Posts
    5
    Hi Sup3rkirby:
    My code is not working, I am working on Firefox and Linux Ubuntu, I don't know if there is some kind of problem with this environment but is not working.
    Can you see some error in my code???
    Let me tell you that this code is inside a Perl script.
    Thanks again.

    Negrazo49

  4. #4
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    903
    Your code from an HTML/Javascript perspective is fine and it does work (tested in Chrome, Firefox, Opera and Internet Explorer). The operating system won't be the source of any sort of coding issue (only the browser). Again the onchange event for textboxes is fired after the textbox loses focus (meaning you must click somewhere else on the page after typing in the textbox).

    If for some reason you are still having trouble (after typing in the box and then clicking somewhere else on the page) then there would likely have to be an error or issue with your Perl script outputting the code. In Firefox you can use the Error Console to view any possible issues that are giving you problems.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  5. #5
    Join Date
    Oct 2012
    Posts
    11
    Try Using IE(internet explorer)
    On the Advance option you have to disable the debugging
    then u might will see the error
    Reagrding the script question I have no clue wut you want ???

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