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);
Related
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 1 year ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I have below html and javascript but on form submission I get an error Method not allowed though I would like to stay on the same index.html and show the success message.
I have debugged the javascript and it bypasses the if condition even I put valid info.
index.html
<form method="post" name="FrmEnquiry" id="FrmEnquiry" onsubmit=" return sendEnquiryform();">
<input name="name" id="name" required="required" placeholder="Your Name">
<input name="email" id="email" type="email" required="required" placeholder="Your Email">
<div class="clearfix"> </div>
<textarea name="message" id="message" cols="20" rows="5" required="required" placeholder="Message"></textarea>
<div class="submit">
<input id="submit" name="submit" type="submit" value="Submit">
</div>
</form>
<span id="sucessMessage"> </span>
javascript.js
var name = $('#name').val();
var email = $('#email').val();
var message = $('#message').val();
$.post('mail.php', '&name=' + name + '&email=' + email + message, function(
result,
status,
xhr
) {
if (status.toLowerCase() == 'error'.toLowerCase()) {
alert('An Error Occurred..');
} else {
alert(result);
$('#sucessMessage').html(result);
}
}).fail(function(xhr, status, error) {
console.log(error); // this shows 'method not allowed' and then i get below alert
alert('something went wrong. Please try again');
});
return false;
}
You need to add action tag to your form.
Like this:
<form method="post" name="FrmEnquiry" id="FrmEnquiry" onsubmit=" return sendEnquiryform();" action="">
You can add the value where you want to send the post to.
Also refer to: https://www.w3schools.com/tags/att_form_action.asp
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 4 years ago.
Improve this question
Some day ago i'd write for asking what was the problem about onclick event doesn't activate when i clicked in a specific area of the browser. After check a guide i find it the problem end also the rappresentation of my simply test is trivial, i've known the mechanism for activating a particular function in browser text area.
Now that work it... i'd want add more detail of my question...what is the mechanism that activate my function from template html to tag <script></script> ?
<h3> Check is palindrome</h3>
<input type="text" id="input1" >
<input type="text" id="input2">
<br><br>
<input type="button" id="reload" onclick="myFunction()" value="ricarica">
<body >
<p onclick="check()" id="output" style="line-height: 1000px"> TEST</p>
</body>
//WHAT IS THE MECHANISM IN THIS POINT FOR ACTIVATE check()?
<script>
function check() {
var x = document.getElementById("input1").value;
var y = document.getElementById("input2").value;
if(x===y){
document.getElementById("output").innerHTML=" E' PALINDROMA "
}else document.getElementById("output").innerHTML=" NON E' PALINDROMA "";
}
function myFunction() {
location.reload(true);
}
</script>
</html>
Everything about your code is wrong. Like... literally everything. Here's a suggested alternative:
var out = document.getElementById('output');
document.getElementById('input').oninput = function() {
if( this.value.split('').reverse().join('') === this.value) {
out.innerHTML = "The input is a palindrome!";
}
else {
out.innerHTML = "The input is not a palindrome...";
}
};
<input type="text" id="input" />
<p id="output">Type something...</p>
From what I understand, move your check() function to the input field
<input type="text" id="text1" onclick="check()">
and remove from body
<body>
This question already has answers here:
how to do file upload using jquery serialization
(7 answers)
Closed 6 years ago.
I have created a form which takes certain input fields and allows a user to upload a file. The form rows are dynamically added by the users. I have used the jquery validation plugin with my form for validation purposes
The problem is i am unable to get the files which has been selected by the users. but all the other fields are being passed.
HTML
<form id="upload">
<table class="dd" width="100%" id="data">
</table>
<input name="sub" type="submit" value="Submit values"/> <input type="button" id="addnew" name="addnew" value="Add new row" />
</form>
JavaScript
$(document).ready(function() {
var currentItem = 1;
$('#addnew').click(function(){
currentItem++;
$('#items').val(currentItem);
var strToAdd = '<tr><td>Year</td><td>:</td><td><select name="year[]" ><option value="2012">2012</option><option value="2011">2011</option></select></td><td width="7%">Week</td><td width="3%">:</td><td width="17%"><select name="week[]" ><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option></select></td><td width="8%"> </td><td colspan="2"> </td></tr><tr><td>Actual</td><td>:</td><td width="17%"><input name="actual[]" type="text" /></td><td width="7%">PDF</td> <td width="3%">: <input id="uploadfile1" name="userfile[]" accept="application/pdf" class="btn btn-next upload" type="file" required></td></tr>';
$('#data').append(strToAdd);
});
$("#upload").validate({
submitHandler: function (form) {
$.ajax({
url: '<?php echo base_url(); ?>/ajax_upload',
type: 'POST',
data: $(form).serialize(),
success: function(data) {
if(data){
alert("success");
} else {
alert("error");
}
},
error: function(data){
alert("error");
},
cache: false,
contentType: false,
processData: false
});
return false;
}
});
});
I have made a test fiddle
Any help will be appreciated.
make the form tag as follows
<form id="upload" action="#" method="POST" enctype="multipart/form-data" >
hope this works
You are not using enctype with form
try
<form id="upload" action="#" method="POST" enctype="multipart/form-data">
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
I'm trying to call a function when submit form , this function showld work for all forms with div "#js_ajax_form".
( the javascript code works in chrome console
// html code
<form method="post" id="js_ajax_form" data-type="user.registration" action="signup">
<input type="text" name="val[first_name]" id="first_name" placeholder="First Name" value="" size="30">
<input type="text" name="val[last_name]" id="last_name" placeholder="Last Name" value="" size="30">
<input type="submit" value="Sign Up" class="button_register" id="js_registration_submit">
</form>
// javascript
var $Core = {};
function getParam(sParam)
{
return oParams[sParam];
}
$Core.form = function()
{
$("#js_ajax_form").submit(function(e)
{
var postData = $(this).serializeArray();
alert(postData);
e.preventDefault(); //STOP default action
e.unbind(); //unbind. to stop multiple form submit.
});
}
as long as you are using jQuery, the following code should work:
$("#myform").submit(function() {
myFunction();
// the form will continue on submission
});
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();
});