Hello all,
I have issue in getting the submit button to do two functions(one after the other) on click.
I am calling two php scripts from those two functions.
1st script saves form data into text file
2nd script changes the location based on radio button inputs
I tried using jquery for changing location based on radio button input, but it works only if i dont use the other function to save the form data.
I have pasted my html and 2 php codes below. please take a look at them and suggest the changes
thanks for looking at the issue.
my html:
<html>
<head>
<script language="Javascript">
function OnButton1()
{
document.form.action = "Input1a.php";
OnButton2();
}
function OnButton2()
{
document.form.action = "Input1b.php";
}
</script>
<!--This function disables the Token Number form if the user clicks "yes" radio button and disables Dataset if "No"-->
<script type="text/javascript">
$(function(){
$("#ex1, #ex2").change(function(){
$("#field1, #field2").val("").attr("readonly",true);
if($("#ex1").is(":checked")){
$("#field1").removeAttr("readonly");
$("#field1").focus();
}
else if($("#ex2").is(":checked")){
$("#field2").removeAttr("readonly");
$("#field2").focus();
}
});
});
</script>
</head>
<body>
<div id="stylized" class="myform">
<form method="post" action="" name="form">
<label> New Data set: </label>
<input type="radio" name="url" value="yes" id="ex1"/> Yes
<input type="radio" name="url" value="no" id="ex2"/> No
<br><br><br>
<label>Dataset description:
</label>
<input type="text" name="dataset" id="field1" value="testing" size="30" placeholder=""><br><br><br>
<label>Token Number : </label><input type="text" name="tokennumber" id="field2" size="6" placeholder=""><br><br><br>
<div style="text-align: center"><br>
<input type="Submit" name="submit" value="Submit" class="submit" onclick="OnButton1();">
<div class="spacer"></div>
</form>
</div>
</body>
</html>
My php input1a
$dataset = $_POST['dataset'];
echo $dataset;
$tokennumber = $_POST['tokennumber'];
echo $tokennumber;
//print("Dataset = $dataset");
$file = "input.txt";
$fp = fopen($file, 'w') or die("Couldn't open $file for writing!");
fwrite($fp, "Dataset = $dataset\n") or die("Couldn't write values to file!");
fwrite($fp, "Token Number = $tokennumber\n") or die("Couldn't write values to file!");
fclose($fp);
$message = "Saved to $file successfully!";
my php input1b
if($_POST['url'] == 'yes') {
header('Location: NetOptInput2.html');
//echo($_POST['url']);
}
elseif($_POST['url'] == 'no')
{
header('Location: NetOptResult2.html');
}