SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    UK
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Selecting a button to press return on?

    Hello

    I have a form with a variety of text boxes, and these have submit buttons to click to submit to the form, eg:

    Code:
    <table>
      <tr>
       <td class='under' style='text-align: right;'>search by title:</td>
        <td class='under'>
             <input name='CCtitleSearch' type='text' value=""  /> 
              <input type='submit' name='CCtitleBtn' id="CCtitleBtn" value='search' class='buttons' />
                 </td>
        </tr>
         <tr>
        <td class='under' style='text-align: right;'>search by course:</td>
          <td class='under'>
        <input name='CCcourseSearch' type='text' value="" onclick="CCbtnFocus();" /> 
          <input type='submit' name='CCcourseSearchBtn' id="CCcourseSearchBtn" value='search' class='buttons' />
          </td>
             </tr></table>
    when I enter the page, the first button is used to submit the form when return key is pressed. What I want to do, is if someone types into the lower box, the 'CCcourseSearchBtn' is selected as the button to be submitted (as if someone had clicked it)

    This didn't work, using the onclick in the CCcourseSearch textbox:
    Code:
    <script language="javascript" type="text/javascript">
       function CCbtnFocus()
       {
         var ccbtn = document.getElementById("CCcourseSearchBtn");
         ccbtn.focus();
       }
    </script>
    Any ideas gratefully received.
    Thanks

    Karl.

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The simplest way is to put each button and their accompanying fields in a form of their own.

    <form name="form1">
    input fields and buttons for form 1
    </form>
    <form name="form2">
    input fields and buttons for form 2
    </form>


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
  •