The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Help me tweak my switch-user script

Go down

Help me tweak my switch-user script

Post by Sarah.givemestories on January 8th 2018, 8:38 pm

So I'm using this script for a switch-user widget I have in my header, always displayed right below my forum's logo.

Code:
<script type="text/javascript">
        function switch_accounts() {
        jQuery.get(document.getElementById('logout').href, function() {
        jQuery.post('/login', 'login=1&username='+document.getElementById('switch_uname').value+'&password='+document.getElementById('switch_pass').value, function () {
        window.location.reload();
        });
        });
        }
        </script>

Something in that function is making it so that the login only works on my forum's home page. When I click the "switch user" button on any other page, nothing happens.

Can someone who knows this code please tell me how to tweak it so the login works on every page?

Here's my forum:
illustrare.forumotion.com
avatar
Sarah.givemestories
Forumember

Posts : 38
Reputation : 2
Language : English
Location : USA

Back to top Go down

Re: Help me tweak my switch-user script

Post by SLGray on January 8th 2018, 8:43 pm

Where did you add this code?


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.

avatar
SLGray
Administrator
Administrator

Male Posts : 42731
Reputation : 3010
Language : English
Location : United States

https://fmthemes.forumotion.com/

Back to top Go down

Re: Help me tweak my switch-user script

Post by Sarah.givemestories on January 8th 2018, 8:44 pm

overall_header template.
avatar
Sarah.givemestories
Forumember

Posts : 38
Reputation : 2
Language : English
Location : USA

Back to top Go down

Re: Help me tweak my switch-user script

Post by SLGray on January 8th 2018, 8:59 pm

Please post your forum's link.


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.

avatar
SLGray
Administrator
Administrator

Male Posts : 42731
Reputation : 3010
Language : English
Location : United States

https://fmthemes.forumotion.com/

Back to top Go down

Re: Help me tweak my switch-user script

Post by Sarah.givemestories on January 8th 2018, 8:59 pm

avatar
Sarah.givemestories
Forumember

Posts : 38
Reputation : 2
Language : English
Location : USA

Back to top Go down

Re: Help me tweak my switch-user script

Post by SLGray on January 8th 2018, 10:14 pm

Could you send me in a PM 2 test accounts to test your code?


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.

avatar
SLGray
Administrator
Administrator

Male Posts : 42731
Reputation : 3010
Language : English
Location : United States

https://fmthemes.forumotion.com/

Back to top Go down

Re: Help me tweak my switch-user script

Post by Sarah.givemestories on January 9th 2018, 4:55 am

So Gray wasn't able to help. Can someone who really knows coding step in?
avatar
Sarah.givemestories
Forumember

Posts : 38
Reputation : 2
Language : English
Location : USA

Back to top Go down

Re: Help me tweak my switch-user script

Post by skouliki on January 9th 2018, 7:23 am

i have this code as a widget 

Code:
  <script type="text/javascript">
        function switch_accounts() {
        jQuery.get(document.getElementById('logout').href, function() {
        jQuery.post('/login', 'login=1&username='+document.getElementById('switch_uname').value+'&password='+document.getElementById('switch_pass').value, function () {
        window.location.reload();
        });
        });
        }
        </script>
        Switch user:<hr />
        <input id="switch_uname" type="text" /><br />
        <input id="switch_pass" type="password" /><br />
        <input type="button" value="Switch user" onclick="switch_accounts();" /> 

avatar
skouliki
Graphic Designer
Graphic Designer

Female Posts : 3495
Reputation : 562
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Re: Help me tweak my switch-user script

Post by Sarah.givemestories on January 9th 2018, 8:43 am

Does it switch accounts on every page besides the index?
avatar
Sarah.givemestories
Forumember

Posts : 38
Reputation : 2
Language : English
Location : USA

Back to top Go down

Re: Help me tweak my switch-user script

Post by skouliki on January 9th 2018, 8:49 am

i think so i havent use it to test it
avatar
skouliki
Graphic Designer
Graphic Designer

Female Posts : 3495
Reputation : 562
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Re: Help me tweak my switch-user script

Post by Sarah.givemestories on January 9th 2018, 10:57 am

Could you please test it and get back to me?
avatar
Sarah.givemestories
Forumember

Posts : 38
Reputation : 2
Language : English
Location : USA

Back to top Go down

Re: Help me tweak my switch-user script

Post by skouliki on January 9th 2018, 12:54 pm

at the moment iam not in a laptop and iam not using it to test it, so better wait for someone else to help you or you could try to test it yourself as a widget (the easiest way)
avatar
skouliki
Graphic Designer
Graphic Designer

Female Posts : 3495
Reputation : 562
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Re: Help me tweak my switch-user script

Post by Sarah.givemestories on January 10th 2018, 9:17 pm

The script is the exact same as mine. It doesn't work. I guess I have to wait until someone can give me another script or help fix mine.
avatar
Sarah.givemestories
Forumember

Posts : 38
Reputation : 2
Language : English
Location : USA

Back to top Go down

Re: Help me tweak my switch-user script

Post by Van-Helsing on January 14th 2018, 10:31 pm

Hello,
As it seems your javascript tries to retrieve a null or missing element:



Please check if you have all the necessary elements in HTML. Otherwise you have to modify your javascript to work with your HTML elements.
avatar
Van-Helsing
Hyperactive

Male Posts : 2410
Reputation : 112
Language : English, Greek

http://helpgr.forumgreek.com/

Back to top Go down

Re: Help me tweak my switch-user script

Post by Sarah.givemestories on January 16th 2018, 7:30 pm

@Van-Helsing wrote:Hello,
As it seems your javascript tries to retrieve a null or missing element:



Please check if you have all the necessary elements in HTML. Otherwise you have to modify your javascript to work with your HTML elements.
 
What do you mean by having all the necessary elements in HTML? How do I do that, exactly?
avatar
Sarah.givemestories
Forumember

Posts : 38
Reputation : 2
Language : English
Location : USA

Back to top Go down

Re: Help me tweak my switch-user script

Post by Van-Helsing on January 16th 2018, 9:01 pm

Hello,
One of your templates using the below code:

Code:
<div class="switchuser"><script type="text/javascript">function switch_accounts() {jQuery.get(document.getElementById('logout').href, function() {jQuery.post('/login', 'login=1&username='+document.getElementById('switch_uname').value+'&password='+document.getElementById('switch_pass').value, function () {window.location.reload();});});}</script><input id="switch_uname" size="6" type="text">&nbsp;&nbsp;<input id="switch_pass" size="9" type="password">&nbsp;&nbsp;<input value="Switch Character" onclick="switch_accounts();" type="button"></div>

This code contains some errors because the element'switch_uname' and / or 'switch_pass' elements are missing in your HTML code of template. Probably is the index_body template. For this reason the get.ElementById function returns error.

avatar
Van-Helsing
Hyperactive

Male Posts : 2410
Reputation : 112
Language : English, Greek

http://helpgr.forumgreek.com/

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum