/    Sign up×
Community /Pin to ProfileBookmark

window.onload run javascript

Hi Guys,

[CODE]
<html>
<head>
<title>642 VGS METAR</title>

</head>
<body>
<h1>642 VGS METAR</h1>

<p><a href=”javascript:location.reload(true)”>Refresh this page</a></p>

<form id=”encode” name=”encoded” align=”center”>

<?php
$location = “EGXU”;

get_metar($location);

function get_metar($location) {
$fileName = “http://weather.noaa.gov/pub/data/observations/metar/stations/$location.TXT”;
$metar = ”;
$fileData = @file($fileName) or die(‘METAR not available’);
if ($fileData != false) {
list($i, $date) = each($fileData);

$utc = strtotime(trim($date));
$time = date(“D, F jS Y g:i A”,$utc);

while (list($i, $line) = each($fileData)) {
$metar .= ‘ ‘ . trim($line);
}
$metar = trim(str_replace(‘ ‘, ‘ ‘, $metar));
}
echo “<input name=”report” readonly=”readonly” value=”$metar” size=”105″ />”;

}
?>
<p>
<input name=”decode” value=”Decode” onClick=”metar_decode(this.form.report.value);” type=”button”>
<p>Decoded Report:</p>
<textarea name=”decreport” cols=”80″ rows=”20″></textarea>
</form>
<script type=”text/javascript” src=”decode_metar.js”></script>
</body>
</html>
[/CODE]

The above page can be found here: [URL=”http://www.theacidfrog.com/attendance/metar.php”]http://www.theacidfrog.com/attendance/metar.php[/URL]

What I want to do is have the form submit onLoad however if you use the standard window.onload thing the page just keep refreshing over and over and never actually displays the result.

Any ideas how to run the decode without having to click the btn.

Cheers, S

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorFeb 22.2011 — Your form has no action. Without an action, or with an empty value of the action, the form will submit onload on the same document. But the submit means changing the session, that means a new onload, a new submit, a new onload, a new submit...

I confess I have not even the slightest idea about what do you want to do on that document.
Copy linkTweet thisAlerts:
@theacidfrogauthorFeb 22.2011 — Haha, thanks for the reply.

The page is going to used for Aviation. Basically a METAR is a weather report, but the report always comes in the format of the top textbox and is brought by the PHP code. This 'decode JavaScript' converts the standard format of METAR Report and 'decodes' it into an easier to read format for newbies. (The bottom text box)

But when I click the submit button it works because its completes a function from the attached decode_metar.js file as shown below

[CODE]<input name="decode" value="Decode" onClick="metar_decode(this.form.report.value);" type="button">
<p>Decoded Report:</p>
<textarea name="decreport" cols="80" rows="20"></textarea>
</form>
<script type="text/javascript" src="decode_metar.js"></script>
[/CODE]


There isnt a form action because Im running the function from the submit button by using the onClick command. But i cant get the page to work automatically without the use of the submit btn. I.e. some sort of on page load run metar_decode(this.form.report.value); similar to the above onclick code...

Any ideas?
×

Success!

Help @theacidfrog 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.27,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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