How to submit onload ?

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
OlivierFR
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Fri Aug 26, 2016 9:28 am

How to submit onload ?

Post by OlivierFR » Fri Aug 26, 2016 6:42 pm

Hi

Can you help me ?
I tried to submit a form (login) on load main page ?

I insert

Code: Select all

$doc =& JFactory::getDocument();
$doc->addScriptDeclaration( onLoad());
but iy s no work

Thank you
Last edited by imanickam on Fri Aug 26, 2016 8:29 pm, edited 1 time in total.
Reason: Moved the topic from the forum Extensions for Joomla! 3.x to the forum Joomla! 3.x Coding

Alejo
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 220
Joined: Fri Aug 19, 2005 12:28 pm
Contact:

Re: How to submit onload ?

Post by Alejo » Sat Aug 27, 2016 2:41 pm

It's not clear to me exactly what you are trying to do, but you can check the documentation for addScriptDeclaration

If you look at the example 2 there:

Code: Select all

function getJavaScript($message) {
    $javascript .= 'if(window.addEventListener){ // Mozilla, Netscape, Firefox' . "\n";
    $javascript .= '    window.addEventListener("load", function(){ alert("' . $message . '");}, false);' . "\n";
    $javascript .= '} else { // IE' . "\n";
    $javascript .= '    window.attachEvent("onload", function(){ alert("' . $message . '");});' . "\n";
    $javascript .= '}';
    return $javascript;
}
 
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration( getJavaScript( 'This will appear in an alert box after the page loads.' ) );
You can see that the getJavasScript function that is passed to the addScriptDeclaration method is defined before and returns a string with javascript code. What does your onLoad function look like?
https://www.jreviews.com/joomla directory, classifieds, and reviews system for Joomla and WordPress

OlivierFR
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Fri Aug 26, 2016 9:28 am

Re: How to submit onload ?

Post by OlivierFR » Sun Aug 28, 2016 6:45 am

Yes it's work.

I modify modules\mod_login\tmpl\default.php

Code: Select all

<?php
function Submit() {
    $javascript .= 'if(window.addEventListener){ // Mozilla, Netscape, Firefox' . "\n";
    $javascript .= '    window.addEventListener("load", function(){ document.getElementById("login-form").submit();}, false);' . "\n";
    $javascript .= '} else { // IE' . "\n";
    $javascript .= '    window.attachEvent("onload", function(){ document.getElementById("login-form").submit();});' . "\n";
    $javascript .= '}';
    return $javascript;
}
 
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration( Submit() );
?>
Thank you


Locked

Return to “Joomla! 3.x Coding”