Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

event bubble

Posted on 2006-07-19
1
Medium Priority
?
323 Views
Last Modified: 2011-09-20
I have one form in a aspx page. I have to have one form due to the design of the runat server elements.

I need the main form to submit when the enter key is press via mainonkeydown(event) or when the submit button is pressed.

However if the focus is in the "searchstring" input then subonkeydown(event) needs to be triggered when the enter key is press and the event that bubbles for the main form onsubmit needs to be cancelled.

I can get the side form to work only when I return false in the form onsubmit. Help.

Sample code below:


<script>
      function mainonkeydown(event)
      {
        if(event.keyCode == 13)
        {
                  document.Form1.submit();
        }
      }
                  
      function subonkeydown(event)
      {
          if(event.keyCode == 13)
        {
        document.location.href='page.aspx?searchstring=' + document.Form1.searchstring.value;
        }
      }
</script>


<form id="Form1" onkeydown="mainonkeydown(event);" method="post">

<input type=text name="searchstring" onkeydown="subonkeydown(event)">
<input type=button value="Go" onclick="document.location.href='page.aspx?searchstring=' + document.Form1.searchstring.value;">

<input type=text name="mainsearch1">
<input type=text name="mainsearch2">
<input type=text name="mainsearch3">
<input type=text name="mainsearch4">
<input type=button value="Submit">

</form>
0
Comment
Question by:hamishd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 30

Accepted Solution

by:
third earned 2000 total points
ID: 17136840
do you mean,

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Author: Third Santor</title>
<script>
  var willReload = false;

  function validate(obj){
    if(willReload){
        window.location = 'page.aspx?searchstring=' + obj.searchstring.value;
//        window.location = 'http://www.google.com';
        return false;
      }
      else{
        //make your usual validation and return depending on the result
        alert('This will submit the form');
        return true;
      }
  }
</script>
</head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<form id="Form1" method="post" onsubmit="return validate(this);">

<input type=text name="searchstring" onfocus="willReload=true;" onblur="willReload=false">

<input type=text name="mainsearch1">
<input type=text name="mainsearch2">
<input type=text name="mainsearch3">
<input type=text name="mainsearch4">
<input type="submit" value="Submit">

</form>
</body>
</html>
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question