/    Sign up×
Community /Pin to ProfileBookmark

onLoad, I hope

Hi all.

I am using the script below which only work when a named field within my FORM has focus. What I want to do is execute the script when the page loads. Can this be done.

<script type=”text/javascript”>

var ajax = new sack();
var currentClientID=false;
function getClientData()
{
var clientId = document.getElementById(‘clientID’).value.replace(/[^a-zA-Z]/i,”);
if(clientId.length==3 && clientId!=currentClientID){
currentClientID = clientId
ajax.requestFile = ‘getClient.php?getClientId=’+clientId; // Specifying which file to get
ajax.onCompletion = showClientData; // Specify function that will be executed after file has been found
ajax.runAJAX(); // Execute AJAX function
}

}

function showClientData()
{
var formObj = document.forms[‘clientForm’];
eval(ajax.response);
}

function initFormEvents()
{
document.getElementById(‘clientID’).onfocus = getClientData;
document.getElementById(‘clientID’).focus();
}

window.onload = initFormEvents;
</script>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Dec 19.2007 — Put it in a function and call the function. That's the best way.
Copy linkTweet thisAlerts:
@dcjonesauthorDec 22.2007 — Hi all.

I need some help with writing a regular expression (I think).

I have a form with an input field and I want to stop unwanted text been entered. The form uses the GET command to retrieve records but over the last week people or machine code has been adding something like this to the end of the query

My URL with correct query:
[code=html]
http://www.mydomain.com/cat/books.php?recordno=121212
[/code]


The type of query that is appearing in my log file is:
[code=html]
http://www.mydomain.com/cat/books.php?recordno=http://some_site_in_russia.com
[/code]


How can I stop this from happening.

Many thanks in advance for any help you can give
×

Success!

Help @dcjones spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...