Radio Button On Click Submit Input [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
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();
});

Related

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.

CodeIgniter PHP: change value in database when checkbox is mark/unmark

Ok, I manage somehow to get value of checkbox, but now i have another issue.
This is my view, rssFeeds.php
<?php foreach( $feeds as $row ) : ?>
<div class="row">
<div class="col-md-2 col-sm-3 text-center">
<a class="story-title"><img alt="" src="http://www.solostream.com/wp-content/uploads/2014/06/20140110080918_0555.jpg" style="width:100px;height:100px"></a>
<label class="checkbox-inline">
<input type="checkbox" class="chkbox" value="chkbox_<?php echo $row->category; ?>_<?php echo $row->id; ?>"> Mark Read
</label>
</div>
<div clas="col-md-10 col-sm-9">
// here are my feeds....
</div>
</div>
<?php endforeach; ?>
I have this script, which take checkbox value, and send it to my controller:
<script>
$(document).ready(function(){
$(document).on('click','.chkbox',function(){
var id=this.value;
$.ajax( {
type: "POST",
context: "application/json",
data: {id:id},
url: "<?php echo site_url('rssFeedReader/markReadUnread'); ?>",
success: function(msg)
{
// what should i do here ?....
}
})
});
});
</script>
In my controller, i just load a model which change a value on my database, 0 or 1( meaning read or unread).
The problem is that nothing change on my table...
I need to put something in that .succes function in ajax ? What.. ? I just need to change one value in my database....
#James-Lalor has the answer you are looking for, but I'll expand upon it.
You can give inputs the same name (radio buttons, checkboxes) to have them interact with each other. In the case of radio buttons it's actually required to have the same name to mark and unmark others. However in this case we will use <input name=example[]> note the [], this means when you do an ajax post (or any post) it will send all the values checked as an array.
So following James' suggestion, you would do a <input name="checkbox[<?php echo $row->id?>]" to which you can post using $.post(url, data, callback), the easiest way to do this would be to put it into a form, assign the form an id, do a serialized post. You could do something like:
<form id="rss_form" method="post" action="javascript:rssUpdate();">
<input name="checkbox[<?php echo $row->id?>]" type="checkbox"/>
<input type="submit" value="submit"/>
</form>
<script>
function rssUpdate()
{
$.post(url/to/post/to, $("#rss_form").serialize());
}
</script>

using javascript in php for php session [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
The Code is:
<?php include 'connection.php';
if($logged_in=='yes')
{
echo "hell yea!"; //just for test and it works
?>
<script type="text/javascript">
alert("test 1 2 3"); //works too.
$("#form1").hide(); //to hide login form, but doesn't work
</script>
<?php
}
?>
I think question is quite clear. What is the reason? Thanks in advance.
EDIT: The session events are work fine by connection.php. No problem logging in or logout etc.
Here is my HTML code:
<div id="form1" name="form1" >
<label for="username"></label>
<input type="text" name="username" id="username" placeholder="Username" class="textbox"/>
<label for="password"></label>
<input type="password" name="password" id="password" placeholder="Password" class="textbox"/>
<span id="submit" class="submit">Log in</span>
</div>
<div>
<span id="logged_in" class="logged_in">Hello user etc.</span> //normally it is hidden from css.
</div>
and here is how I login:
$("#submit").click(function(){
$.ajax({
type:"POST",
url:"login.php",
data: '{"username":"'+$("#username").val()+'","password":"'+$("#password").val()+'"}',
dataType: "json",
success: function(data) {
if(data.ok=="done!"){
$("#form1").hide();
$("#giris").show();
$("#giris").html('Hello '+data.name+' '+data.lastname+' My Account');
}
else if(data.ok=="No such user!")
alert("No such user");
else
alert(data.ok); //activation required
}
});
});
EDIT: alert() line. HTML code added. Jquery part is added. And this forum tells me my post is mostly code so I think I have type something here. And I think I just did.
Try this code. Hope it will work.
<?php include 'connection.php';
if($logged_in=='yes')
{
echo "hell yea!"; //just for test and it works
?>
<script type="text/javascript">
$(document).ready(function(){$("#form1").hide(); });
</script>
<?php
}
?>
where dou you get tehe value of the session????
<?php
session_start();
// store session data
$_SESSION['logged_in']='yes';
?>
then
<?php include 'connection.php';
//////if($logged_in=='yes')
if(isset($_SESSION['logged_in']) && $_SESSION['logged_in']=='yes')
{
echo "hell yea!"; //just for test and it works
?>
<script type="text/javascript">
$("#form1").hide(); //to hide login form, but doesn't work
</script>
<?php
}
?>
check this link: http://www.w3schools.com/php/php_sessions.asp
I hope this help you men!

Javascript isn't working with Jquery and ajax [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 8 years ago.
Improve this question
<div class="RegisterFrame">
<form method="post" id="form" action="registeration.php" class="reg" enctype="multipart/form-data">
<input type="file" class="fileChooser" name="img">
<div class="uploadimg" name="imgUploader"><img src="" name='IDpic' class="IDpic"></div><br>
<text>Username</text><input type="text" class="textBox" name="user"><br>
<text>Password</text><input type="password" class="textBox" name="pass"><br>
<text>re-enter your password</text><input type="password" class="textBox" name="repass"><br>
<text>e-mail</text><input type="text" class="textBox" name="email"><br>
<text>re-enter your e-mail</text><input type="text" class="textBox" name="reemail"><br>
<button class="Con" type="submit">Done O.o</button><button class="Res" type="button">reset</button>
</form>
</div>
==========================================
Script code :
$("#form").submit(function(e) {
e.preventDefault();
// alert('test');
data = new FormData($('#form')[0]);
// console.log('Submitting');
$.ajax({
type: 'POST',
url: 'registeration.php',
data: data,
cache: false,
contentType: false,
processData: false,
success: function(result) {
alert(result);
//PS: the result gives the correct full path yet the image doesn't change
document.getElementsByClassName('.IDpic').src=result;
}
});
});
.getElementsByClassName('.IDpic').
I'm guessing the classname does not include a dot - this should be .getElementsByClassName('IDpic').
Also, since you are using jQuery, might as well do
$('.IDpic').attr('src', result);

Auto Submit Form not working [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
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!!

Categories

Resources