Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    getting enter to behave like onclick button

    i know similar problems have been posted, but i'm new at this and wasn't able to apply the solutions. i have a form with a text box that submits using onclick with a button. when i click on the button, it goes to a function that decides which url should be brought up. when i hit enter, it goes to the url defined in the action= of the form. how do i make enter go to the function?

    <form name=gcFormKeywords method=get
    action="http://url/script.pl">
    <b> </b>
    <input type=text name="search" size=30>
    <input type=button value="Go" onClick=gcGo() name="button">
    </form>

    where gcGo is (something like) the following (actually, i've expanded it, but the structure is the same):

    function gcGo(searchType) {
    var searchType = document.gcFormSearchType.search.selectedIndex;
    // index 0 is the keywords option; index 1 is the symbol option; index 2 is the gc id option
    // alert(searchType);
    // alert(document.gcFormKeywords.search.value);
    if (searchType == 1) {
    var re = /\*/
    if (re.exec (document.gcFormKeywords.search.value)) {
    document.gcFormSymStar.symsearch.value =
    document.gcFormKeywords.search.value;
    document.gcFormSymStar.submit();
    }else {
    document.gcFormSymbol._symbol.value =
    document.gcFormKeywords.search.value;
    document.gcFormSymbol.submit();
    }
    } else{
    if (searchType == 2) {
    var re = /\*/
    if (re.exec (document.gcFormKeywords.search.value)) {
    document.gcFormSymStar.symsearch.value =
    document.gcFormKeywords.search.value;
    document.gcFormSymStar.submit();
    }else {
    document.gcFormGcid.gc_id.value =
    document.gcFormKeywords.search.value;
    document.gcFormGcid.submit();
    }
    }else {
    document.gcFormKeywords.submit();
    }
    }
    }

    there are 3 or 4 forms after the one quoted above. each sends to a different url.

    tia,
    naomi

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try using your function as the form action.

    eg:<form name=gcFormKeywords method=get
    action="javascript&#58;gcGo()">


    .....Willy

  • #3
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Bad practice, Willy.

    See this:
    Code:
    <form action="http://server.domain/path" onsubmit="return checkForm(event, this);">
       <input type="text" name="term" />
       <input type="submit" value="Go!" />
    </form>
    
    ...
    <script type="text/javascript">
    function checkForm (evt, aForm) {
       // run routines on subelements of the 'aForm' object - it's a reference to the form itself
       if (/* all validation passes */) {
          return true;
       }
       return false;
    }
    </script>

  • #4
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    choopernickel-
    you lost me a bit. my grasp of js is tenuous at best (i was handed this code and asked to modify it. i managed to add functionality, but i couldn't remove the original bug). can you apply that to my code and tell me what it's supposed to be doing? thanks much.
    naomi

  • #5
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'd love to, but not with just what you supplied. If you can attach the code that the browser sees (view source instead of attaching from your editor), I'd be happy to take a closer look.

  • #6
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the code is long, tedious, complex, and (as far as i can tell) the view source code looks identical to the editor code (shouldn't it?). are you wondering about the pieces i didn't include?

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    don't know what browser ur using but both IE and FF fire onclick on both enter and when you click with the mouse

  • #8
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks to everyone. i gave up on the js and got it to work by doing all the processing in a perl script. i'm much more in my element that way....


  •  

    Posting Permissions

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