www.webdeveloper.com
Results 1 to 3 of 3

Thread: window.onload run javascript

  1. #1
    Join Date
    Nov 2009
    Posts
    9

    Unhappy 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>
    The above page can be found here: http://www.theacidfrog.com/attendance/metar.php

    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

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    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.

  3. #3
    Join Date
    Nov 2009
    Posts
    9
    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>
    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?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles