SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: submit disabled

  1. #1
    SitePoint Addict
    Join Date
    May 2006
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    submit disabled

    hi, I need a little help. I want to make this kind of thing - only when 3 characters are written in the text field - submit enables, otherwise it is disabled

    HTML Code:
    <INPUT TYPE="radio" NAME="answer" VALUE="$key" onClick="document.getElementById('poga').disabled=false"> $value
    <INPUT TYPE="Submit" id="poga" NAME="vote" VALUE="Balsot" disabled=disabled>
    it's easy with radio button, but don't know how can I make it with text field

  2. #2
    SitePoint Addict
    Join Date
    May 2006
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    on the second thought maybe I should count the number of letters and than display information in alert box? only was there a function that counts the number of letters ( str ... something like that ). and where do I have to check if there's 3 characters entered? at the end of the form or at the start of php file?

  3. #3
    SitePoint Guru toasti's Avatar
    Join Date
    Feb 2004
    Location
    Grahamstown
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should do the trick:

    Code:
    <script>
    function checkLen(){
       input = document.getElementById('txt');        
       if(input.value.length>3){
          document.getElementById('sbt').disabled = false;
       }else{
          document.getElementById('sbt').disabled = true;
       }
    }
    </script>
    <input type = 'text' onkeypress="javascript:checkLen()" id="txt" name="txt" />
    <input type = submit id="sbt" name="sbt" disabled=disabled />
    ..this isnt really ideal, cause the checkLen() function is actually called everytime the user presses a key anywhere on the screen. You can also use the onblur event instead of onKeyUp. This will fire when the textbox looses focus. so it isnt as immediate as the onKeyUp event...

    ..it seems like there should be a better way of doing this.

    Also, this is javascript, not php..
    Last edited by toasti; Jul 4, 2006 at 02:12. Reason: onkeyup is not supported by IE. use onkeypress

  4. #4
    SitePoint Addict
    Join Date
    May 2006
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There will be a problem with this, cause when the user clicks into the text field, the submit won't be disabled. it will be disabled only when 1, 2 or 3 characters are written.

  5. #5
    SitePoint Guru toasti's Avatar
    Join Date
    Feb 2004
    Location
    Grahamstown
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just make the submit disabled by default?
    (i updated the form so the submit is defaulted to disabled)

  6. #6
    SitePoint Addict
    Join Date
    May 2006
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tnx, will try it

  7. #7
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    But as already said - this is not a PHP question! I know you are using PHP as your back-end coding, and we here in the PHP board are helpful, but please try to keep questions to the right board.
    Ian Anderson
    www.siteguru.co.uk

  8. #8
    SitePoint Addict
    Join Date
    May 2006
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    firstly I wanted to do this with php function. btw how is it called? something like str...

  9. #9
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    strlen()

    but php runs on your webserver, not in the users browser. so they could still submit the form, but your php code doesnt need to accept it if the data doesnt validate.

  10. #10
    SitePoint Guru toasti's Avatar
    Join Date
    Feb 2004
    Location
    Grahamstown
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    firstly I wanted to do this with php function
    you wouldnt be able to do this with PHP. PHP is server side.
    btw how is it called
    how is what called?

  11. #11
    SitePoint Guru toasti's Avatar
    Join Date
    Feb 2004
    Location
    Grahamstown
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    strlen()
    oh!


Bookmarks

Posting Permissions

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