Reputation: 2094
this is my code ,can any one help me . onclick
function is not calling on click function insert1(); is not calling when i am clicking onclick button.even if i am using the script in head part also it is not working.
<html>
<head>
<?php
$mode="";
$sno="";
$name="";
$gender="";
$age="";
if(isset($_REQUEST["mode"]))
$mode=$_REQUEST["mode"];
else
$mode="LIST";
if($mode=="save"){
$sno=$_REQUEST['sno'];
$name=$_REQUEST['name'];
$gender=$_REQUEST['gender'];
$age=$_REQUEST['age'];
$con = mysqli_connect("localhost","root","","forsight");
$sql="insert into atomica (name,gender,age) values ('$name','$gender','$age')";
mysqli_query($con,$sql);
}
?>
</head>
<body>
<?php
if($mode=="LIST"){
?>
<center>
<pre>
sno <input type ="text" name=sno id=sno readonly ><br>
name <input type =text name=name id=name ><br>
gender <input type =text name=gender id=gender ><br>
age <input type =text name=age id=age><br>
<input type=button onclick="insert1();" value=insert><br>
<input type="button" onClick="fnsave();" class="button" value="Save">
</center>
<?php
}
?>
<script>
function insert1()
{
alert("t");
var sno=document.getElementById("sno").value;
var name=document.getElementById("name").value;
var gender=document.getElementById("gender").value;
var age=document.getElementById("age").value;
window.location="file3.php?sno="+sno+"&name="+name+"&gender="+gender+"age="+age+"&mode="save";
}
</script>
</body>
</html>
Upvotes: 3
Views: 190
Reputation: 873
("age"+age+)("&mode="save"), Solution("&age"+age+)("&mode=save")
window.location="file3.php?sno="+sno+"&name="+name+"&gender="+gender+"&age="+age+"&mode=save";
Upvotes: 4
Reputation: 7694
There is an Error in your Javascript, this is why the method is not working.
window.location="file3.php?sno="+sno+"&name="+name+"&gender="+gender+"age="+age+"&mode="save";
See the
"&mode="save";
Should be:
"&mode=save";
Also @bhavesh found the other error in your vars, this doesn't block JS from working but creates a wrong URL.
Upvotes: 7