Problem related to PHP and Javascript

Pensu

Pensu

@pensu-8tNeGU Oct 15, 2024
Hello ppl, i am coding for a website and i want to run this code. But i dont know why its not running.

<html>
<script type="text/javascript">
function check()
{
var name=document.form1.uname.value;
if(name=="peeyush")
{
	windows.location.href="https://localhost/welcome.php";
}
}
</script>
<body>

<form name="form1">
  Username:
  <input type="text" name="uname" />
  
  Password:
  <input type="password" name="pwd" />
  
  
    <input type="submit" onClick="check()" />
  
</form>

</body>
</html>
It should redirect on page welcome.php, but the result is the page itself. Can anyone plz help me with this, or if you know any other method to redirect to a PHP page after validation from Javascript.

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • slashfear

    slashfear

    @slashfear-tSWzpz Mar 21, 2011

    Hi Peeyush,

    I am not able to run and test this code 😔 for some reason my Apache is not working... any way I run through your script and found that You have used input type of submit button so when you use the submit button by default it will take you to the location what you have specified in the action attribute in the form since you have not specified any action attribute its is showing you the same page so, you can change the input type to be button and then use the onClick event handler or you can specify onSubmit event handler in the form definition.

    And also in the javascript function check(), in order to redirect to another page you can use window.location = "somelocation"

    If you have any doubts please feel free to ask..... 😀

    -Arvind
  • Pensu

    Pensu

    @pensu-8tNeGU Mar 21, 2011

    well...onclick() is working fine....and i tried window.location. Same result...😔
  • Rahulmarkan

    Rahulmarkan

    @rahulmarkan-YLEUFZ Mar 21, 2011

    i am beginner of shopping cart application. i am installed os commerce downloaded code in my local computer. It is up some extent working, but before checking page i stuck on same page.
    i am trying to pass variable information to javascript function, it is working. And i required to set java script variable set to session. how can ?
    i am trying to those values to appending with url path, i.e add & to url and append those variables. but its not appending in my web browser address bar. but that variable information is perfectly shown in alert box of javascript function.
    so i think creating form is something better, how can i?
    how to create form in oscommerce application?
  • Morningdot Hablu

    Morningdot Hablu

    @morningdot-6Xuj4M Mar 22, 2011

    use
    <input type="Button" onClick="check()" />
    insted of
    <input type="submit" onClick="check()" />
    on more thing it's window not windows.Window is default so you can also write location.href.
    And if again it's not working(may be the reason your server is on different port then 80(default)).
  • slashfear

    slashfear

    @slashfear-tSWzpz Mar 22, 2011

    nicepeeyush
    well...onclick() is working fine....and i tried window.location. Same result...😔
    Why its not working ?? It will work!! Here is my modified code (with the changes I told you in my previous reply) which is tested and working!!

    <html>
    <script type="text/javascript">
    function check()
    {
    var name= document.form1.uname.value;
    if(name == "slashfear")
    {
            window.location="https://google.com";
    }
    }
    </script>
    <body>
    
    <form name="form1">
      Username:
      <input type="text" name="uname" />
      
      Password:
      <input type="password" name="pwd" />
      
      
        <input type="button" value="send" onClick="check()" />
      
    </form>
    
    </body>
    </html>
    
    
    -Arvind