woolyg Posted November 3, 2008 Share Posted November 3, 2008 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 Quote Link to comment Share on other sites More sharing options...
xtopolis Posted November 4, 2008 Share Posted November 4, 2008 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 4, 2008 Share Posted November 4, 2008 <?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> Quote Link to comment Share on other sites More sharing options...
woolyg Posted November 4, 2008 Author Share Posted November 4, 2008 mjdamato - I spent a bit of time, and worked it out - Thats almost *exactly* the code I went for! Nice one guys, thanks for your input. WoolyG Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.