AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Off-Topic (https://forums.alliedmods.net/forumdisplay.php?f=15)
-   -   JavaScript help (https://forums.alliedmods.net/showthread.php?t=145536)

Rirre 12-17-2010 10:46

JavaScript help
 
In need of help with JavaScript.
I'm trying to make a checkbox with a submit button which you have to check to redirect/continue to the 'newpage.php' file.

You don't get redirected to 'newpage.php' when you check the checkbox and submit. It just refresh the current page you are on.
PHP Code:

<html>
<
head>
<
script language=javascript>
function 
validate(chk){
  if (
chk.checked == 1)
    
window.location='newpage.php';
  else
    
alert('You have not agreed!')
}
</script>
</head>

<body>
    <form>
        <input type='checkbox' name='chk1' /> Agree<br />
        <input type='image' src='images/continue.jpg' align='right' onclick='return validate(chk1);' />
    </form>
</body>
</html> 

Appreciate all help.

Seta00 12-17-2010 10:54

Re: JavaScript help
 
Quote:

Originally Posted by Rirre (Post 1372810)
You don't get redirected to 'newpage2.php' when you check the checkbox and submit. It just refresh the page.

Quote:

Originally Posted by Rirre (Post 1372810)
PHP Code:

    window.location='newpage.php'



joaquimandrade 12-17-2010 14:18

Re: JavaScript help
 
The problem with your code is that by clicking the image your are submitting the form and the action of your code to change the page gets overriden.
Code:

<html>
<head>
<script language=javascript>
function validate(chk){

  if (chk.checked == 1)
    window.location='newpage.php';   
  else
    alert("You have to agree");
}
</script>
</head>

<body>
    <form onsubmit="validate(chk1);return false">
        <input type='checkbox' name='chk1' /> Agree<br />
        <input type='image' src='images/continue.jpg' align='right' />
    </form>
</body>
</html>


Seta00 12-17-2010 14:20

Re: JavaScript help
 
Dead people don't talk.

joaquimandrade 12-17-2010 15:44

Re: JavaScript help
 
Quote:

Originally Posted by Seta00 (Post 1372939)
Dead people don't talk.

:)

Rirre 12-17-2010 21:43

Re: JavaScript help
 
Quote:

Originally Posted by joaquimandrade (Post 1372937)
The problem with your code is that by clicking the image your are submitting the form and the action of your code to change the page gets overriden.
Code:

<html>
<head>
<script language=javascript>
function validate(chk){

  if (chk.checked == 1)
    window.location='newpage.php';   
  else
    alert("You have to agree");
}
</script>
</head>

<body>
    <form onsubmit="validate(chk1);return false">
        <input type='checkbox' name='chk1' /> Agree<br />
        <input type='image' src='images/continue.jpg' align='right' />
    </form>
</body>
</html>


Thank you :)


All times are GMT -4. The time now is 01:36.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.