-1

Ok I'm trying to auto login a guest account and it requires:

In header

<script language="JavaScript" type="text/JavaScript">
    function guestLogin() { 
        document.form_login.username.value = 'guest'; 
        document.form_login.password.value = 'guest'; 
        document.form_login.submit(); 
    }
</script>

And

<form action="https://www.redcheetah.com/WebPrefex/" method="post" name="form_login">
    <input name="username" type="text" value="" />
    <input name="password" type="password" value="" />
    <input name="form_action" type="submit" value="Login" />
</form>

javascript:guestLogin(); 

How would I get the javascript:guestLogin(); to work without having the Login form on the page.

Any Tips?

Thanks

trixn
  • 15,761
  • 2
  • 38
  • 55
  • 1
    This is confusing. Are you saying there is no login form in the body? Or are you saying that you don't want to show the login form if the user is already logged in? – Victor Stoddard Apr 23 '18 at 22:36
  • https://stackoverflow.com/questions/8003089/dynamically-create-and-submit-form – CarlRosell Apr 23 '18 at 22:38
  • I saying I need the form to be there for the javascript:guestLogin(); to work.. but i dont want to see it. – glenn kline Apr 23 '18 at 22:54

1 Answers1

1

If you need the form to be on the page - if you can't create it on demand for whatever reason - then if you want guestLogin to work without the user seeing the form, you'll have to hide the form using CSS. It'll still be submittable, it just won't be visible:

function guestLogin() {
  document.form_login.username.value = 'guest';
  document.form_login.password.value = 'guest';
  console.log('submitting');
  document.form_login.submit();
}
document.querySelector('div').onclick = guestLogin;
form {
  display: none;
}
<form action="https://www.redcheetah.com/WebPrefex/" method="post" name="form_login">
  <input name="username" type="text" value="" />
  <input name="password" type="password" value="" />
  <input name="form_action" type="submit" value="Login" />
</form>
<div>click to submit</div>
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320