Jump to content

[SOLVED] Calling onLoad halfway down a page?


woolyg

Recommended Posts

Hi all,

 

I've got a piece of code that is half way down a PHP page. It calls a JS script, depending on whether a SESSION variable is set.

 


<?php
if((isset($_SESSION['one_to_many_input_choice']) && ($_SESSION['one_to_many_input_choice'] == "one_by_one"))){ // IF 27

$method_of_retrieval = "onload";

} else {

$method_of_retrieval = "onkeyup";

}
?>

 

 

Then..

 


<html>

<input name="number_of_recipients" id="number_of_recipients" <?php echo $method_of_retrieval; ?>="one_to_many_show_recipient_list()"/>

</html>

 

.. This essentially dictates the method of the one_to_many_show_recipient_list() call. If the SESSION variable is not set, the JS is called when the user types on their keyboard. If it is set, I'd like the page to automatically carry out the JS.

 

However, the 'onload' side of it doesn't want to work for me. Is there another way of automatically calling one_to_many_show_recipient_list() - similar to onload - without needing the user to physically do anything?

 

I hope I've been clear, I'm quite new to JS. All input appreciated.

Thanks,

WoolyG

 

 

onload is only supported by the following tags:

<body>, <frame>, <frameset>, <iframe>, <img>, <link>, <script>

 

so putting onload on an input will not work.  you could possibly make php put that into the body tag if the result is onload.

<?php
if((isset($_SESSION['one_to_many_input_choice']) && ($_SESSION['one_to_many_input_choice'] == "one_by_one")))
{ // IF 27
    $body_onload = ' onload="one_to_many_show_recipient_list();"';
    $input_onkeyup = '';
}
else
{
    $body_onload = '';
    $input_onkeyup = ' onkeyup="one_to_many_show_recipient_list();"';
}
?>

 

<html>
<body<?php echo $body_onload; ?>>
<input name="number_of_recipients" id="number_of_recipients"<?php echo $input_onkeyup; ?> />

</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.