Nancy
Nancy

Reputation: 143

Page not redirected when button is pressed

<html>
<head>
</head>
<body>
<script>
function isVisible(){
    if(document.getElementById("nt").checked==true){
         document.getElementById("opt").style.visibility="hidden";  
    }
    else{
         document.getElementById("opt").style.visibility="visible";
    }
} 
</script>
<form align="center" method="post">
<input type="radio" name="teaching" id="t" value="teaching" onchange="isVisible()"> Teaching<br>
<input type="radio" name="teaching" id="nt" value="non-teaching" onchange="isVisible()"> Non-teaching<br>
Post Code <input type="text" name="pcode" id="pcode"><br>
Post Name <input type="text" name="pname" id="pname"><br>
<div id="opt">
Department <input type="text" name="dept" id="dept">
</div>
<input type="button" name="addv" id="addv" value="Add Vacancy"  onclick="javascript: form.action='hello.php';">
</form>

</body>
</html>

Above is addvacancy.php. On clicking button Add Vacancy, it is not directing to hello.php. It remains on the same page with values in the text boxes retained. Below is the code for hello.php.

hello.php

<html>
<head>
</head>
<body>
<?php
echo "Hello!";
?>
</body>
</html>

Upvotes: 0

Views: 30

Answers (1)

mferly
mferly

Reputation: 1656

You need to add an action to your form, and you should remove the onclick event from your input so it looks like this:

<input type="submit" name="addv" id="addv" value="Add Vacancy">

And add an action to your form that points to the desired URL in which your form submission will be directed to, so it looks like this:

<form action="hello.php" align="center" method="post">

That should do the trick. The action attribute tells the browser to send the form data to a form-handling PHP page.

Upvotes: 1

Related Questions