473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to prevent onload function to fire more than once?

3
Hi All

I have a onload event which calls a function in Javacsript which has some logic to be executing.

Expand|Select|Wrap|Line Numbers
  1. <body onload="display()">
  2. function display()
  3. {
  4. my logic goes here which creates a html table based on query results 
  5. }
I have a text box with search button, when clicked calls another function. This works fine if i click the button direclty. But when i press enter key, it calls the required function and then automatically calls the onload function. This is happening only in firefox, works in IE.

Expand|Select|Wrap|Line Numbers
  1. display += '<input type="text" id="quick_Code" size="15" name="Template" onkeydown=\"javascript:if((event.which &amp;&amp; event.which == 13) || (window.event.keyCode &amp;&amp; window.event.keyCode == 13)){document.getElementById(\'btnSearch\').click();return false;}else return true;\" />'; 
I'm not sure whats wrong with my code.
Nov 30 '10 #1
4 2426
Dormilich
8,658 Expert Mod 8TB
what kind of variable is display?
Dec 1 '10 #2
saps
3
Display is a variable used to assign the HTML code to Div tag
Expand|Select|Wrap|Line Numbers
  1. <body class="Custom46Tab overviewPage" Onload="display();">
  2. <div class="" id="displayScreen"></div>
  3. </body>
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("displayScreen").innerHTML = display; 
Dec 1 '10 #3
Dormilich
8,658 Expert Mod 8TB
Doh, should have seen earlier.

when you use display you’re actually referring to the display() function. you should definitely rename that. Do you have any messages in the error console?
Dec 1 '10 #4
saps
3
Thanks Dormilich for your reply.
Even renaming did not work for me.
Problem is once the return key event triggers the button click, it calls the function and then automatically reloads the page. This works if I press the button manually by clicking it. Problem is only with firefox.

Expand|Select|Wrap|Line Numbers
  1. display += '<input id="btnSearch" class="btn" type="button" size="10" value="'Template Search" onclick="keywordSearch();"/>'; 
Dec 1 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Arpan De | last post by:
Suppose I have the following ASP code: <% Dim strName ..................... ..................... ..................... ..................... ..................... .....................
1
by: Red Ogden | last post by:
The following script returns an error saying document.all is null or not an object when I try to call the write_layer function more than once within the same else statement i.e.: else {...
2
by: brian | last post by:
question about Onload function can one define more than one function for Onload ? <body Onload="function1()"> or can one define multiple functions one after another like <body Onload="f() g()...
20
by: modemer | last post by:
Question is as in subject. For example: class BaseClass { public: void func() { do something; } // I don't want this function being overloaded in its inherited class };
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
2
by: Praveen | last post by:
Hi, Any one ever used getopt function more than once. Here is my example. I have to run a process as myProcess -x -y -c "-a -f myFile -o myOutput -d debugFile" First I have to check for -c...
1
by: jamierphelps | last post by:
I'm sure you guys are tired of seeing this kind of message, but this is hopefully something a little different. I searched first. I am using Drupal for a site and I also want to use Nifty Corners...
1
by: zebra242 | last post by:
I'm working to get the onLoad function of a javascript to work: the script allows form buttons in html to refer to labeled frames in flash. Which works fine. Now I want to add onLoad...
1
by: Bexm | last post by:
Hello! I want to use the Application Begin Request to store some global values in the context each time a page loads but the begin request event fires more than once? I have a master page with...
1
by: Jorge | last post by:
On Oct 23, 10:36 am, Tuxedo <tux...@mailinator.comwrote: Yes: function first_function (PARAMETER) { preload_image = new Image(800,600); preload_image.onload = function () {...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.