Hello all,
I am trying to call two functions onclick of a submit button. the two functions inturn go to two php scripts..i want the php scripts to be run one after the other.
But, its not working. Please take a look at my code and suggest some changes
my html :
<form method="post" action="" name="form">
<label> New Data set: </label>
<input type="radio" name="url" value="NetOptInput2.html" id="ex1" required/> Yes
<input type="radio" name="url" value="NetOptResult2.html" id="ex2" required/> No
<br><br><br>
<label>Dataset description:
</label>
<input type="text" name="dataset" id="field1" size="30" placeholder="" readonly><br><br><br>
<label>Token Number : </label><input type="text" name="token" id="field2" size="6" placeholder="" readonly><br><br><br>
<div style="text-align: center"><br>
<input type="Submit" name="submit" value="Submit" class="submit" onclick="return(OnButton2() && OnButton1())">
<div class="spacer"></div>
</form>
My Javascript
<!-- this function navigates user according to the radio button selection-->
<script language="Javascript">
function OnButton1()
{
document.form.action = "Input1a.php"
// document.form.target = "_blank"; // Open in a new window
//document.form.submit(); // Submit the page
// return true;
}
function OnButton2()
{
document.form.action = "Input1b.php"
//document.form.target="_blank";
// document.form.submit(); // Submit the page
// return true;
}
<!--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();
}
});
});
MY php file1
if (isset($_POST) && $_POST['url1'] == "Yes")
{
header('Location: NetOptInput2.html');
}
else if (isset($_POST) && $_POST['url2'] == "No")
{
header('Location: NetOptResult2.html');
}
my php file 2
if (isset($_POST['submit'])) {
$dataset = $_POST['dataset'];
$tokennumber = $_POST['tokennumber'];
$data = "$dataset | $tokennumber\n";
$file = "input.txt";
$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!");
fclose($fp);
$message = "Saved to $file successfully!";
}