Testing for focus

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Irwin

    Testing for focus

    I'd like to prevent a submit button from getting focus unless a particular
    textbox or radio button is selected.

    For example, if a user clicks anywhere within a form, the submit button is
    focused and will submit whatever data is present if the user accidentally
    presses Enter/Return. I would like to prevent this from happening unless
    the user's cursor is within a textbox or the selection is on a radio button.
    Is this possible? I believe this only happens with IE/Win.


  • HikksNotAtHome

    #2
    Re: Testing for focus

    In article <O%2hb.21908$Sn 1.21316@bignews 4.bellsouth.net >, "Mike Irwin"
    <mike@faroutfre akyshit.com> writes:
    [color=blue]
    >I'd like to prevent a submit button from getting focus unless a particular
    >textbox or radio button is selected.
    >
    >For example, if a user clicks anywhere within a form, the submit button is
    >focused and will submit whatever data is present if the user accidentally
    >presses Enter/Return. I would like to prevent this from happening unless
    >the user's cursor is within a textbox or the selection is on a radio button.
    >Is this possible? I believe this only happens with IE/Win.[/color]

    <input type="submit" onFocus="checkO therField()" name="mySubmit" >

    function checkOtherField (){
    if (!document.some Form.someObject .checked){
    document.someFo rm.mySubmit.blu r()
    }
    }

    Or:

    <input type="submit" onFocus="
    if (!document.some Form.someObject .checked){this. blur()}
    " name="mySubmit" >

    Although, a better all around solution is to use the onSubmit of the form to
    check it, instead of focus:

    <form name="someForm" onSubmit="retur n checkOtherField ()">

    function checkOtherField (){
    if (!document.some Form.someObject .checked){retur n false}
    else{return true}
    }


    --
    Randy

    Comment

    • Mike Irwin

      #3
      Re: Testing for focus


      "HikksNotAtHome " <hikksnotathome @aol.com> wrote in message
      news:2003100823 1958.15462.0000 3455@mb-m06.aol.com...[color=blue]
      > <input type="submit" onFocus="checkO therField()" name="mySubmit" >
      >
      > function checkOtherField (){
      > if (!document.some Form.someObject .checked){
      > document.someFo rm.mySubmit.blu r()
      > }
      > }
      >
      > Or:
      >
      > <input type="submit" onFocus="
      > if (!document.some Form.someObject .checked){this. blur()}
      > " name="mySubmit" >
      >
      > Although, a better all around solution is to use the onSubmit of the form[/color]
      to[color=blue]
      > check it, instead of focus:
      >
      > <form name="someForm" onSubmit="retur n checkOtherField ()">
      >
      > function checkOtherField (){
      > if (!document.some Form.someObject .checked){retur n false}
      > else{return true}
      > }[/color]

      Thanks for the reply, Randy. I believe this will work.


      Comment

      Working...