SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    HI silver trophy Silverado4x4's Avatar
    Join Date
    Jan 2001
    Location
    USA
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right now, the page will only pop up if the user clicks the submit button. I would like it to pop up when someone presses the enter button. How would I do this?

    Here is the code I am using:
    Code:
    <form action="http://www.jokes-central.com/cgi-bin/maillist/mojo.cgi">
    <input type="hidden" name="flavor" value="subscribe">
    <input type="hidden" name="list" value="Updates_And_Jokes">
    <input type="text" name="email" size="10" value="your e-mail">
    <input type="submit" value="Subscribe" 
    onClick="window.open('http://www.jokeemail.com/jc_thankyou.htm')">
    </form>
    Last edited by Silverado4x4; Mar 25, 2001 at 19:43.

  2. #2
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    In IE, I think when you press enter, it should automatically submit the form, but I guess that doesn't fire the onclick event handler.

    Your best bet is to use the onsubmit event handler in the form and not use an event handler in the submit button itself. Then, we can make NN (and IE) submit the form when they press enter.

    Code:
    <script>
    function getKey(e){
    	keyCode = navigator.appName=="Netscape"?e.which:event.keyCode;
    	if(keyCode == 13){
    		document.form1.submit();
    	}
    }
    if(document.layers)document.captureEvents(Event.KEYPRESS)
    document.onkeypress = getKey;
    </script>
    
    <form name="form1" action="http://www.jokes-central.com/cgi-bin/maillist/mojo.cgi" onSubmit="window.open('http://www.jokeemail.com/jc_thankyou.htm')">
    <input type="hidden" name="flavor" value="subscribe">
    <input type="hidden" name="list" value="Updates_And_Jokes">
    <input type="text" name="email" size="10" value="your e-mail">
    <input type="submit" value="Subscribe"></form>
    If by using the submit() method, it doesn't fire the onsubmit event handler, just use:


    Code:
    		document.form1.submit();
    		window.open('http://www.jokeemail.com/jc_thankyou.htm');
    aDog

  3. #3
    HI silver trophy Silverado4x4's Avatar
    Join Date
    Jan 2001
    Location
    USA
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bingo! You nailed the problem


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
  •