Auto Submit Form not working [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Using this open source file:
https://raw.github.com/openemr/openemr/master/interface/billing/sl_eob_search.php
I want to do auto submit form and is not responding.
I am using as reference this Auto populate form and auto submit with URL Parameters
which is what I would like to do - submit URL parameters but is not working.
REVISED
1st I added an id to the <form>, left the "values" on the textbox unchanged as I'm passing those values via URL.
<form method='post' action='sl_eob_search.php' id='search_invoice'
enctype='multipart/form-data'>
.
.
.
<td>
<input type='text' name='form_pid' size='10'
value='<?php echo $_POST['form_pid']; ?>'
title='<?php xl("Patient chart ID","e"); ?>'>
</td>
<td>
<?php xl('Encounter:','e'); ?>
</td>
<td>
<input type='text' name='form_encounter' size='10'
value='<?php echo $_POST['form_encounter']; ?>'
title='<?php xl("Encounter number","e"); ?>'>
</td>
.
.
.
<td>
<input type='submit' name='form_search' id='search'
value='<?php xl("Search","e"); ?>'>
</td>
.
.
.
</form>
SUBMIT BUTTON
I added an "id" attribute, and after the </form> closed:
<script type="text/javascript">
$(document).ready(function() {
$("#search").submit();
});
</script>
It didn't work... then went and got the form id:
document.forms['search_invoice'].submit();
And nothing happens.

You have used the id of the submit field (search):
<script type="text/javascript">
$(document).ready(function() {
$("#search").submit();
});
</script>
You should use the id of the form instead:
<script type="text/javascript">
$(document).ready(function() {
$("#search_invoice").submit();
});
</script>

Solved it by using click instead of submit!!
$(document).ready(function(){$("#search").click();});
Thanks!!

Related

Sending to checked checkbox which is linked to email [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
So I'm new to coding such as Javascript and PHP, I need to create a form that will be hosted on a site which on a submit will send an email dependent on which checkbox is ticked, the different checkboxes will go to different emails, would I need to use a PHP post for this and is there any need for Jquery at all? or could I just use PHP? would love the help. Thank you
<?php
$mail1 = "test#test.com";
$mail2 = "test2#test.com";
$mail3 = "test3#test.com";
if(isset($_POST["MainCB"])) {
$mail1 = $_POST["MainCB"];
}
if(isset($_POST["ITCB"])) {
$mail2 = $_POST["ITCB"];
}
if(isset($_POST["CateCB"])) {
$mail3 = $_POST["CateCB"];
}
if(isset($_POST['submit'])){
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$MainCB = $_POST['MainCB'];
$ITCB = $_POST['ITCB'];
$CateCB = $_POST['CateCB'];
$subject = "Form submission";
$message = $first_name . " " . $last_name . " " . $MainCB . " " . $ITCB . " " . $CateCB;
}
?>
<html>
<head>
<title>Form submission</title>
</head>
<body>
<form action="" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Maintenance:<input type="checkbox" id="MainCB"><br>
IT: <input type="checkbox" id="ITCB"><br>
Catering: <input type="checkbox" id="CateCB"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
You can create a form like this
<form action="mail.php" method="POST">
<input name="checkbox1" value="email1#yahoo.com" type="checkbox"></input>
<input name="checkbox2" value="email2#gmail.com" type="checkbox"></input>
<button type="submit">Test</button>
</form>
And in your mailing script you can retrieve the checkbox value.
if(isset($_POST["checkbox1"])) {
$mail1 = $_POST["checkbox1"];
}

Submitting a PHP upload once files have been selected [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have an image upload script using PHP with a simple multiple file select and then an upload function like below:
mysql_connect("localhost", "root", "") or die("error");
mysql_select_db("repo") or die("error");
$imgerror = '';
if(isset($_POST['log'])){
foreach($_FILES['files']['tmp_name'] as $key => $name_tmp){
$name = $_FILES['files']['name'][$key];
$tmpnm = $_FILES['files']['tmp_name'][$key];
$type = $_FILES['files']['type'][$key];
$size = $_FILES['files']['size'][$key];
$dir = "content/images/".$name;
$move = move_uploaded_file($tmpnm,$dir);
if($move){
$hsl = mysql_query("insert into files values('','$client','$name','$type','$size',now())");
if ($hsl){
$imgerror = "IMAGE(S) UPLOADED SUCCESSFULLY";
} else {
$imgerror = "CANNOT CONNECT TO DATABASE";
}
} else {
$imgerror = "NO IMAGES SELECTED";
}
}
}
HTML:
<div class="uploadContainer">
<div><i><?php echo $imgerror ?></i></div>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="files[]" multiple>
<input type="submit" name="log" value="Upload">
</form>
</div>
I did find some information using jQuery from another question here but have no idea how I would implement this into my code, or maybe someone could suggest an alternative. All I am trying to do is select the files, and make it automatically submit without pressing a submit button.
Any help would be appreciated,
Thanks
The onchange event works for inputs type file. Next code auto-submits "once files have been selected" (tested in Mozilla Firefox) :
<html>
<head>
<script type="text/javascript">
function on_change ()
{ alert( "File(s) chosen!" +
"\n\n" +
"Click to submit files to upload." );
document.getElementById( "frm" ).submit();
}
</script>
</head>
<body>
<form id="frm" action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="files[]" multiple onchange="on_change()">
<input type="submit" name="log" value="Upload">
</form>
</body>
</html>
Of course, you will have to remove the JavaScript "alert" window, it's there to show that the "onchange" event works.

website upload file to directory [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need to create website to upload a file into a directory inside called "Uploads". I was wondering how to do this with HTML, JavaScript and/or PHP. I am new to website building. Thanks.
Try this:
<form id="form_request_file" method="post" action="index.php" enctype="multipart/form-data">
<table align="center" width="525" border="0">
<label for="uploaded" class="control-label col-sm-2">Upload File</label>
<input id="uploaded" name="uploaded" type="file"/>
<input value="Submit" name="submit" type="submit"/>
</form>
<?php
if (isset($_POST['submit'])) {
if (isset($_FILES['uploaded'])) {
$path = "uploaded_docs/";
$file_name = basename($_FILES['uploaded']['name']);
$target = $path . $file_name;
if (move_uploaded_file($_FILES["uploaded"]["tmp_name"], $target)) {
echo $file_name . " was uploaded";
} else {
echo "Could not upload";
}
}
}
?>

How to submit one form out of multiple with javascript

On my website I have a big list of all the letters people can view.
For every letter there is a form which sends some data from the letter to the next page. What I want to do is to submit the form with a link, and not with a button.
As far as I know, that is not possible with PHP. So i tried making what i want in Javascript.
My programming experience in Javascript is litterly 0%. I need some help with this :)
This is the code I'm using:
<script type="text/javascript">
function submitform()
{
document.forms["brief_weergeven"].submit();
}
</script>
<form id='brief_weergeven[]' action='<?php echo $main; ?>beveiligd/achterbanner/nieuwsbrief.php' method='POST'>
<input type='hidden' name='nummer' value='<?php echo $brieven[0]; ?>'>
<input type='hidden' name='datum_maand' value='<?php echo $maand_getal; ?>'>
<input type='hidden' name='datum_jaar' value='<?php echo $jaar; ?>'>
<a href="javascript: submitform()" class='button'>Nieuwsbrief <?php echo $brieven[0]; ?> (<?php echo $maand .' ' .$jaar; ?>)<BR></a>
</form>
This code runs for every letter. As you can see, I'm using a array to give all the forms a seperate ID. The only thing is that i have no idea how to let javascript know which forum i submitted.
How can I do this? Please remember that i know nothing about javascript, so please explain what you're doing in your answer.
You dont need javascript to do this, just use css to make your button look like a link:
Css:
button {
border:none;
padding:0;
background: none;
color: blue;
text-decoration: underline;
cursor: pointer;
}
html:
<button type="submit">Submit</button>
You can usedocument.getElementById('form-id')
And event handler like this
var form = document.getElementById('your-form-id');
form.onsubmit = function(){
// code
}
user574632 gave you a nice alternative. Still even want to use JavaScript you can try below.
Use the jQuery onclick method having the id attribute of the link as selector.
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("#submit_link").on("click", function(){
var form = $(this);
var url = form.attr("action");
var data = form.serialize();
$.post(url, data);
});
});
</script>
<form id='brief_weergeven[]' action='<?php echo $main; ?>beveiligd/achterbanner/nieuwsbrief.php' method='POST'>
<input type='hidden' name='nummer' value='<?php echo $brieven[0]; ?>'>
<input type='hidden' name='datum_maand' value='<?php echo $maand_getal; ?>'>
<input type='hidden' name='datum_jaar' value='<?php echo $jaar; ?>'>
<a href="#" id="submit_link" class='button'>Nieuwsbrief <?php echo $brieven[0]; ?> (<?php echo $maand .' ' .$jaar; ?>)<BR></a>
</form>

Radio Button On Click Submit Input [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How can i make when i chose a radio button On or Off to submit input id="kot" ?
<label><input type="radio" onClick="*???*" name="shfaq<?php echo $i; ?>" value="1" id="radiobuttonsondazh_0" <?php if($result['live']==1) echo 'checked'; ?> />Po</label>
<label><input type="radio" onClick="*???*" name="shfaq<?php echo $i; ?>" value="0" id="radiobuttonsondazh_1" <?php if($result['live']==0) echo 'checked'; ?> />Jo</label>
<input id="kot" name="soralivetitull" type="submit" value="Shfaq" style="margin-top:1em" onclick="setWTF(this.form.soralivetitull);" />
Try it like this:
<script type="text/javascript">
function submitform()
{
document.forms["myform"].submit();
}
</script>
//give your form the id "myform"
<form id="myform" action="submit-form.php">
//and then call the function onCLick
<input type="radio" onClick="javascript: submitform()" ...
Either you can make a form out of this and do something explained here:
W3Schools on form submitting
or you can make a submit function via ajax:
$.ajax({
url: 'MyURLtoReceivePost',
type: 'POST',
cache : false,
data : data,
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
success: function (response) {
console.log(response);
},
error: function () {
console.log("error");
}
});
In which you could just include your own data {parameter_name : value, parameter_name2 : value2}
The information you can easily find in the jquery API
http://api.jquery.com/submit/
$( "#radiobuttonsondazh_0" ).click(function() {
$( "#kot" ).submit();
});

Categories

Resources