Unobtrusive Script Event Keeps Executing On Page Load / Fix It?

Oct 10, 2011

I have a simple button in my HTML. I also have a function in my external JavaScript file. This function calls an alert box with some text. Now, I also have a global variable in my JavaScript that gets the button by id, then assigns the onclick event handler to it which in turn is assigned the call to my alert box function. Simple right?

Problem: The alert box shows up when the page loads as well as when the button is clicked. This is not desirable. code...

View 14 Replies


ADVERTISEMENT

Executing A Function On Page Load ?

Oct 28, 2010

Test Page: http:[url].........

Code below:

<script language="JavaScript">
function function1(){
window.scrollTo(0,265);[code].....

Question: Is it possible to get rid of the button and have it scroll to 0,265 on page load ?

Comment: <body onload="function1();"> doesn't appear to work.

View 1 Replies View Related

Unobtrusive - Remove Event Handing From The Markup?

Jul 12, 2009

From my understanding the main feature of unobtrusive JavaScript is to remove event handing from the markup.The main reason for doing this is to avoid repetition of code.There are also other reasons but that is the main one. e.g. no having to write <tag onclick="function()" > over and over again. This traditional event handling method makes code less maintainable.However is it worth writing unobtrusive code when we consider the following:

1, Server sider scripting laguages can be used to avoid code repetition. e.g. we can use a loop to add multiple onclick event handlers to all the elements of a navigation list. Thus we would only have to write onclick="function()" once.

2, Unobtrusive coding makes the code harder to follow.It is easier to look at the markup to find out what happens when an event occurs on an element rather than having to look through wades of JS code to find the correct event listener. This is especially true when a team is working on a project. It is easier to find out what another person has done when the traditional model of event handling is used.

3, Unobtrusive coding means longer and more complicated code. Also there there is a need for having to deal with browser differences.I know this can be reduced using libraries such as JQuery. Is it worth using such a library?

View 2 Replies View Related

JQuery :: Event Click - After Load Page

Feb 27, 2010

Is there a way to add event click on link created by dom after load page ?

View 2 Replies View Related

Javascript Event Handling And Page Load

Nov 13, 2007

I understand that when loading a page, the html parser is suspended until any script that it comes across is executed. i also believe that certain browsers will allow user input for those parts rendered whilst the rest of the page is still being parsed. suppose that a user clicks a button that is visible and 'active' and fires off some lengthy javascript execution causing the ui to 'freeze' for a while. my question is, on a page that is still being parsed but allows user input on those parts parsed and rendered, will the parsing of the rest of the page cease whilst the event handler (onclick) is working or will the user see the page render simultaneously as the event handler does its job?

View 7 Replies View Related

Trigger An Onchange Event On Page Load?

Jan 25, 2011

I have this onchange event that occurs after user selection of a dropdown menu. When a user makes a selection it queries the database and delivers some data.

The value of the dropdown is stored in a database, but the problem is when the page is refreshed the delivered data disapears, only reappearing if you change the dropdown.

How can I make the onchange event run when the page loads so that if there is already a selection, the database data will always be there, only to change if the user changes the selection?

Here is the JS:
<script type="text/javascript">
function showCustomer(str)
{var xmlhttp;

[Code].....

View 14 Replies View Related

JQuery :: Unable To Trigger A Event On Page Load?

Aug 1, 2009

I bind a custom event on page A,then ajax load page B。In page Bthereis a <a> link which trigger the custom event.Problem is :the trigger function work when i place the trigger
function in page A ,but not work in B by ajax load.

View 1 Replies View Related

JQuery :: Bind Causes Click Event To Raise On Page Load?

Dec 31, 2011

I'm using the following code to attach a method to the click event of my button. It definitely works, but unfortunately the click event happens on page load even though no one has actually clicked on the button. How do I prevent this? $('#btn').bind('click',etCategories());

View 4 Replies View Related

Safari Not Sending Requests During The Onclick Event Due To New Page Load?

Jul 7, 2010

I have a site which displays a selection of advert listings. We log the number of clicks each advert receives via ajax requests.The listings link to both internal pages on our site and external pages, hence the ajax - we cannot log the'clicks' by logging the requests on the destination pages as these are not all on our site for us to log. Also, I don't want to potentially get false positives e.g.from bookmarked pages - hence I am logging the actual clicks, not the requests on the destination.

All is OK in most browsers, but there is a problem with Safari (I am running Safari 4.0 on Windows XP running in Virtualbox OSE) but only where the destination is to open in the same window/tab (some listings go to a new window, some don't). I am logging clicks via an ajax request in the onclick event, which is working fine when the listing is to open in a new window, but it appears that when a new window is not to be opened, the ajax never gets sent.A have constructed the following minimal test case:

index.html

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" [code].....

Note the line commented '****' in index.html which cancels the action of the link. When this is not commented out, the ajax request is sent correctly. Without it (the desired situation) the ajax request never gets sent. Its as if Safari saves up the ajax requests to do later, but never sends them as the new page cancels all such 'saved up' actions.I am using the Safari web developer tools, but I have also checked this test case by checking the Apache logs. Note that as a test case I don't pretend that it will work in IE, but it should work in standards compliant browsers and has been tested on Firefox 3.6.6 and Opera 10.6. The Apache logs show that logger.txt is being requested, unless it is already in the browser cache.Possible workarounds I've considered, but would prefer to avoid:

On the site in question the only such links that currently open in the same window are internal, so I do have the option of logging safari clicks by logging these requests as opposed to clicks and checking the http referer on the server side. As this is not a very flexible solution as it relies on these specific circumstances, also relies on all other links successfully making a new window, and furthermore relying on http referer could result in false negatives I'd rather find a solution within the javascript.I haven't checked whether an asynchonous request would work, but I don't wish to do this anyway just in case there is ever a server problem that prevents the response coming back (note that for these purposes the response is actually superfluous - we are sending the server a message but don't need anything back). I also want to avoid the delay in sending the user to the destination - there is no point having to wait for a response we don't need.Lastly, and my prefered workaround unless I can find anything better, is to make Safari (only) open all links in a new window anyway.

View 1 Replies View Related

JQuery :: Executing Code On Blur Event?

Dec 2, 2010

I am doing a simple function to validate text fields(you can see the code below). Now, the alert box appears only once when I refresh the page, not when I click inside or outside the username box. #username is the id of a input text field. On a sidenote, how can I pass multiple parameters to the function(not a fixed number of params)? or should I just pass an array?

[Code]...

View 1 Replies View Related

OnClick Event Handler Not Executing In <input> Tag

Feb 8, 2010

I have a button on a page that is created with the <input> statement - this statement also contains the event handler onClick. The button displays correctly on the page but the event handler is not working - I know this as I put a simple alert at the beginning of the function PrcsBtn1.

<script type="text/javascript" language="javascript">
function PrcsBtn1()
{
var data2 = new Array();

[Code]....

View 2 Replies View Related

Function Called By Onload Event Not Executing Fully?

Jan 28, 2009

I am having issues with the following bit of code:

function test(){
window.alert("Alert1");
var testvar = document.getElementById("topMenu").getElementsByTagName("li");

[code]....

View 2 Replies View Related

Which Method Will Make The Page Load Faster - Calling Code From A .js File 50 Times Slow Down Page Load?

May 12, 2011

I have a single webpage that contains information on all 50 U.S. states. There are 50 links at the top to jump down to the state you want, and at the bottom of the information for each state a Back to Top link.

I'm making the Back to Top link into something more complex, and it will require three or four lines of code.

So that I don't have to repeat the code 50 times, and create a burden when I need to edit it, I want to place it in a .js file and call it x. Then below the information for each state I'll simply have:

Does calling code from a .js file 50 times slow down the page load? Which method would load faster?

View 3 Replies View Related

Code Not Executing In Web Page ?

Aug 22, 2010

For 2 day ago, i have re-read and re-write my code in first i have very very broken code execution in web in second :, i re write the code and in previewer browser ( i use mozilla 3.6.8) its work off line, but when i have implanting in web page, its not work, in 3rd, with mr.airshow support i have rewrite and it work on web page (thanks mr. airshow) but still in my mind, again :

Question :

1. Why the 2nd code can not execution in web page ?

2. How the code must be to load in web page ? Any rules ?

Here are the code :

View 2 Replies View Related

Stop Executing On A Page?

Oct 6, 2011

Is there a piece of code I could put in my website that will allow the same effect as the user disabling javascript in browser options? That would mean that it would stop any javascript from even executing? I would put it on an event.

View 9 Replies View Related

Extension Stops Executing After Reaching Some Page?

Sep 21, 2011

I have written a chrome extension which will redirect to all hrefs for a given source urls in current tab.. But i don't know why all of a sudden it stops executing after reaching some page. I am attaching my code as attachment.

View 1 Replies View Related

Manually Executing A Function In An HTML Page?

Nov 3, 2009

Is it possible to execute a JS function in a website, by using the JS console? Facebook has a function Facebook.streamPublish() for instance, which displays a dialog box to send a story to your Wall.Is it possible to call this from the JS console manually?I'm developing a Facebook application. I tried to call the above function from the Firebug console to test but with no success.

View 4 Replies View Related

Load Before Page Loads - Slow Down The Actual Page Load Of The Website

Jan 30, 2009

I have some javascript code that does some GET and POST requests that are required. Sometimes it doesn't fully execute for the user because they close or click onto another page before the javascript is completely done. Is there anyway I can let all of the javascript load first and slow down the actual page load of the website.

View 3 Replies View Related

JQuery :: Document Ready Not Executing When Page Loads

Jan 4, 2012

I have an html page with a lot of JavaScript functions that all work fine. Then I decided to add a jQuery function, but the document ready is not executing when the page loads. As you can see below I've added the document.ready function at the top of the page, below the links. And below that are the JavaScript functions that were there all along. Why the document ready function doesn't execute? (I don't see the "ready" alert, and the jQuery isn't working.)

<link rel="stylesheet" type="text/css" href="css/real.css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
alert("ready");
$(".CheckBoxClass").change(function(){
if($(this).is(":checked")){
alert("adding LabelSelected class");
$(this).next("label").addClass("LabelSelected");
}else{
$(this).next("label").removeClass("LabelSelected");
}});
});
</script>
<script type="text/javascript" language="javascript">
function showImage(image) {
image.style.visibility="visible";
} function hideImage(image) {
image.style.visibility="hidden";
}

View 1 Replies View Related

Unobtrusive Over / Down / Click

Jan 24, 2007

Is it possible to write this as and unobtrusive script in the head of a document?
This is a really long piece of code for being in the html!

<a href="whatever" onmouseover="document.images['s3a'].src='hover.gif'" onmouseout="document.images['s3a'].src='root.gif'" onmousedown="document.images['s3a'].src='active.gif'" onmouseup="document.images['s3a'].src='hover.gif'"><img src="root.gif" name="s3a" height="50" width="50" alt="" border="0"></a>

View 2 Replies View Related

Unobtrusive Script With Parameters?

Nov 12, 2009

I have a PHP page that dynamically generates table rows with input fields. A sample row looks like:

Code:
<tr id="row1">
<td><input type="button" name="remove_row1" id="remove_row1" value="X" /></td>
</tr>

I have a JavaScript function that I am attempting to attach to each of the input buttons:

Code:
// get all the input elements
var inputs = document.getElementsByTagName('input');
var delete_regex = new RegExp('remove_row');[code]...

But I would like to give it a parameter

Code: inputs[i].onclick = delete_row('row' + inputs[i].id.replace('remove_row', ''));

But doing the above just executes the function. What is the best way to do this?

View 2 Replies View Related

Unobtrusive Fixed DIV For All Browsers

Mar 3, 2010

First off by let me stating that I am not a great web devloper nor am I a good with css / javascript. I am creating this website for a friend of mines company and I have one problem.The problem is that the navigation menu on the right side will not remain fixed how i want it to be. I spoke with many people and they all said that this cannot be done with css considering your layout and because it needs to dodge the headers and the footer. I basically want this div (sidenav on the right) to scroll along the page as users scroll up or down but it can not interfere with the header or footer. I do not want the right side navigation to go over the content or out of the wrapper. I want it to stay in the same position in all aspects - left / right / top / bottom. Here is a link to the site [URL].

View 2 Replies View Related

Best Practice For Unobtrusive Javascript

Oct 16, 2007

I have been going back and getting rid of so many of my onclick's and such, trying to switch to a more unobtrusive method of adding events to anchors.

I've run into one snag that's kind of dissonant for me, and wondered if anyone had any advice.

By adding an event, you can turn:

<a href="#" onclick="something(); return false;>Click me</a>

Into:

<a href="new.html" class="something">Click Me</a>

But what goes in href if you don't have anything to actually link to? One example is a page I've written that is entirely self-contained, and all href's that drive the interface end up pointing to #. Is this acceptible in edge cases like these with the unobtrusive approach?

If someone has JS turned off the markup is essentially meaningless, so I was wondering how people deal with this lapse in the separation between behavior and structure.

View 2 Replies View Related

Make Unobtrusive Work All The Time?

Jul 11, 2009

I'm working on implementing an unobtrusive javascript where I use code instead of an HTML hook to call a function.

Old way: <input type="text" name="username" onBlur="javascript:function();" />

Now I have changed it to:

window.onload = function()
{
if(document.getElementById("username"))
{
var usernameInput = document.getElementById("username");
usernameInput.onblur = checkUsername('username','ajaxResponse');
}
}

which is placed in the body section of the page. Anyhow, my problem is that it works fine, but only once, right as the page loads. I have tried removing window.onload, but then it doesn't work at all. How can I get this to work every time I blur from the text field?

View 1 Replies View Related

Unobtrusive Way To Show/hide Divs

Jan 10, 2007

I've got the following code in a website of mine:

Code:

<a href="section1.htm">Section 1</a>
<a href="section2.htm">Section 2</a>
<a href="section3.htm">Section 3</a>
<a href="section4.htm">Section 4</a>

<div id="general">General overview</div>

<div id="section1">Section 1 overview</div>
<div id="section2">Section 2 overview</div>
<div id="section3">Section 3 overview</div>
<div id="section4">Section 4 overview</div>

I want to display the div marked 'General overview' by default, and to hide all of the other divs (section1, section2, section3 and section4) but would like to swap out the 'general' div with the other divs as the corresponding links are moused over.

e.g. mousing over the Section 2 link will replace the 'general' div with the 'section2' div. On mousing out, it will revert back to the 'general' div. Mousing over the Section 4 link will replace the 'general' div with the 'section4' div. On mousing out, it will revert back to the 'general' div. Etc etc....

View 11 Replies View Related

Passing Parameters To An Unobtrusive Function?

Jul 10, 2007

I was reading through a book that talked about unobtrusive javascript, and it gave this example of how to trigger a function instead of using an inline onmouseover event handler.

document.getElementById("RandomElementId").onmouseover=RandomFunction;
I thought this would be cool, but I can't seem to find a way to pass parameters to the function this way. I assumed you just use RandomFunction(parameter1,parameter2); but no go.

Is there a different syntax for this, or does this technique forbid using parameters?

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved