Solved

event bubble

Posted on 2006-07-19
1
307 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 500 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

724 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