I am having a task that the form contains different inputs. Before going to save the data the user has to go for preview. Preview is loading in a modal popup which contains some inputs. In the inputs presented in modal popup is loaded with the values entered by the user in the form. i have written some code. but when i click on preview it was not loading in modal popup. can anybody help. my code goes here
<html>
<head>
<script src="jquery.min.js"></script>
<script src="bootstrap-3.4.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="bootstrap-3.4.1/css/bootstrap.min.css">
</head>
<script type="text/javascript">
$(document).ready(function(){
$('#preview').click(function(){
var f_name=$('#name').val();
$('#name1').val(f_name);
});
});
</script>
<div class="modal-body">
1. Name of the Applicant <input type="text" name="name1" id="name1" required />
</div>
Name of the Applicant
<input type="text" name="name" id="name" maxlength="50" required />
<button id="preview" class="btn btn-danger btn-sm">Preview</button>
Related
Does anyone know how to change the name of the button 'Select file' and 'No file selected' that appears in the following image?
It seems that it is a button that comes by default from googleapis.com. I cannot change the name to English, could you help me? Thank you.
Is there the same button but in English?
This is the code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<div align="center">
<label class="selectCSV">Select the CSV file:</label>
<input type="file" name="file" />
<br/><br/>
<input type="submit" name="submit_exercises" value="Import" class="btn btn-info" />
</div>
</form>
</body>
</html>
If I'm correct, the text on and next to the button depends on the language of the browser and the browser itself. The text cannot be changed.
However, by utilising JS and some CSS, you can hide the original button, add your own and 'redirect' the click on the fake button to the actual file input.
The snippet below utilizes vanilla JavaScript and does not show the name of the file.
document.getElementById('fakeButton').addEventListener('click', redirectToFileInput);
function redirectToFileInput () {
document.getElementById('fileInput').click();
}
#fileInput {
display:none;
}
<input type="file" id="fileInput" name="file">
<input type="button" id="fakeButton" value="YourText">
The snippet below utilizes jQuery and shows the filename after selecting it in the upload window.
$(document).on('click', '#fakeButton', function(event) {
event.preventDefault();
$("#fileInput").click();
});
$("#fileInput").change(function(){
$("#fileName").text(" " + $('input[type=file]')[0].files[0].name);
});
#fileInput {
display:none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="file" id="fileInput" name="file">
<input type="button" id="fakeButton" value="YourText"><span id="fileName"> No file uploaded.</span>
Edit: Cleaner solution for the vanilla javascript answer.
#fileInput {
display:none;
}
<input type="file" id="fileInput" name="file">
<input type="button" id="fakeButton" value="YourText" onclick="document.getElementById('fileInput').click();">
I am unable to load external file while using AJAX jQuery. I want to use jQuery AJAX to pop up form then validate, enter data in MySQL. but starting from a simple AJAX function. Kindly let me know where I am going wrong
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="test_style.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script>
<script>
$(document).ready(function(){
$("#ajax-contact-form").submit(function(){
var str = $(this).serialize();
$.ajax({
type: "POST",
url:"contact.php",
data: str,
success:function(result) {
$("#div1").html(result);
}
});
});
});
</script>
</head>
<body>
<div id="contact_form">
<form id="ajax-contact-form" name="contact" action="">
<fieldset>
<label for="name" id="name_label">Name</label>
<input type="text" name="name" id="name" size="30" value="" class="text-input"/>
<label class="error" for="name" id="name_error">This field is required.</label>
<input class="button" type="submit" name="submit" value="Send Message">
</fieldset>
</form>
</div>
</body>
</html>
and contact.php file is
<?php
echo "Hello";
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="test_style.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function() {
$(".button").click(function() {
$.ajax({url:"contact.php",success:function(result){
$("#div1").html(result);
}});
return false;
});
});
</script>
</head>
<body>
<div id="contact_form">
<form name="contact" action="">
<fieldset>
<label for="name" id="name_label">Name</label>
<input type="text" name="name" id="name" size="30" value="" class="text-input" />
<label class="error" for="name" id="name_error">This field is required.</label>
<input type="submit" name="submit" class="button" id="submit_btn" value="Send" />
</fieldset>
</form>
</div>
<div id="div1">
</div>
</body>
</html>
Try that:
What needed to be fixed:
1) You'd duplicated the onReady function,
2) you can use a submit form button, but since it's default action is to submit the form, the result wouldn't have been visible.
3) There was no #div1 for the result to be displayed in.
Hopefully, this has been helpful... Happy Coding!
Try with type button type
<input type="button" name="submit" class="button" id="submit_btn" value="Send" />
And also your both scripts are same use either DOM ready or $(function) like
<script>
$(document).ready(function(){
$(".button").click(function(){
$.ajax({url:"contact.php",success:function(result){
$("#div1").html(result);
}});
});
});
</script>
button is your class name so that it will represented like .button And create an div with id div1 at your html page
$("#div1").html(result);
Use one div which id is div1 inside your page which you want to show the result.
<div id="div1"></div>
I am working on a MailChimp subscription form that will need to send the form $_POST data to MailChimp, but not actually load the success page. I.e. I want it to load custom JS on submission. This is what I have so far. Obviously the preventDefault is breaking the submission. Any thoughts are greatly appreciated:
<!-- Begin MailChimp Signup Form -->
<link href="http://cdn-images.mailchimp.com/embedcode/slim-081711.css" rel="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<style type="text/css">
#mc_embed_signup{background:#fff; clear:left; font:14px Helvetica,Arial,sans-serif; }
</style>
<form action="http://yourmove.us5.list-manage.com/subscribe/?u=00000444444333331&id=aaa111444iiii" method="POST" id='mc_embed_form'>
<div id="mc_embed_signup">
<h3>Subscribe to <em>Our Newsletter/em> for your free download:</h3>
<input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder="email address" required>
<div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button" novalidate></div>
</div>
</form>
<script type="text/javascript">
$(document).ready(function(){
$("#mc_embed_form").submit(function (){
event.preventDefault();
showConfirmation();
});
});
function showConfirmation() {
alert("successful");
}
</script>
You are missing a parameter in your function, try this one:
$(document).ready(function(){
$("#mc_embed_form").submit(function (event){
event.preventDefault();
showConfirmation();
});
});
I use LiveValidation on a submission form that involves 1-4 upload fields for images.
What the clients are impatient about is that once they click on submit, the form starts to upload the images, and it takes time according to the size of those images.
What I was trying to achieve is that once the user submits the form, and the LiveValidation passes, a Fancybox popup appears which has a loading image and some text. I do not want the loading progress bar as the client's hosting does not have the PECL upload progress extension or APC, and I don't want to use AJAX for compatibility reasons.
I just want a loading image to be rotating on the screen so the user knows that they have to wait.
I tried to create a function for it and set it to be executed on the events of "onSubmit" and "onClick", but in either case, the pop up appears even though there are errors in the form that are being pointed out by LiveValidation.
Also, i am assuming that once the images get uploaded and the form gets submitted the page will automatically redirect to the confirmation.
I am not good with javascript, and hence was unable to manipulate the scripts to achieve the desired results.
Any help on this will be greatly appreciated. Also if anyone has a better solution, that too will be great!
Thank you :)
for live validation, I'm using the script directly from the website: http://livevalidation.com/
Here is the livevalidation and fancybox initiation:
<script type="text/javascript">
$(document).ready(function () {
$(".form-validate-label").validate();
$(".form-validate-p").validate({errorElement: "p"});
$(".popup").fancybox();
});
</script>
The form itself is pretty big, but here is the fields area:
<form name="frmsubmission" id="frmsubmission" method="post" class="form-validate-p" enctype="multipart/form-data" action="">
...
...
<div class="regrow1">
<div>
<label class="label-large"><span class="required">*</span>Headshot Image File:</label>
<input class="required" name="head_shot" id="head_shot" size="40" type="file" />
</div>
</div>
<div class="regrow2">
<div>
<label class="label-large">Attach Resume:</label>
<input name="txtcv" id="txtcv" size="40" type="file" />
</div>
</div>
<div class="regrow1">
<div>
<label class="label-large">Full body shot Image File:</label>
<input id="body_shot" name="body_shot" size="40" type="file" />
</div>
</div>
<div class="regrow2">
<div>
<label class="label-large">Sanpshot Image File:</label>
<input id="snap_shot" name="snap_shot" size="40" type="file" />
</div>
</div>
<br /><br />
<div id="submitrow">
<button id="submit" name="submit" value="Submit" type="submit">Submit</button>
</div>
</form>
instead of using fancybox and others approach. if you use plupload, i think that it will nice uload interface and upload status feature. below is the link.please see this may help you.
http://www.plupload.com/example_queuewidget.php
instead of show fancybox, i added one div with its loadingId. initially it will be hidden when you click, submit button it show the div, inside this div, you rotating image path. here is complete code.
i am using jquery for hide show. if you do not want to use jquery, you can use javascript also for hide and show.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="Js/LiveValidation.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".form-validate-label").validate();
$(".form-validate-p").validate({ errorElement: "p" });
$(".popup").fancybox();
});
function showloading() {
$("#loadingId").show();
}
</script>
</head>
<body>
<form name="frmsubmission" id="frmsubmission" method="post" class="form-validate-p"
enctype="multipart/form-data" action="">
<div class="regrow1">
<div id="loadingId" style="display:none;">Loading....</div>
<div>
<label class="label-large">
<span class="required">*</span>Headshot Image File:</label>
<input class="required" name="head_shot" id="head_shot" size="40" type="file" />
</div>
</div>
<div class="regrow2">
<div>
<label class="label-large">
Attach Resume:</label>
<input name="txtcv" id="txtcv" size="40" type="file" />
</div>
</div>
<div class="regrow1">
<div>
<label class="label-large">
Full body shot Image File:</label>
<input id="body_shot" name="body_shot" size="40" type="file" />
</div>
</div>
<div class="regrow2">
<div>
<label class="label-large">
Sanpshot Image File:</label>
<input id="snap_shot" name="snap_shot" size="40" type="file" />
</div>
</div>
<br />
<br />
<div id="submitrow">
<button id="submit" name="submit" value="Submit" type="submit" onclick="showloading();">Submit</button>
</div>
</form>
</body>
</html>
Hi all I am making a contact form popup window on my website using Jqmodal. The contact form loads and displays correctly, but the contact form itself I am trying to submit it using ajax and then want to give the user a message saying "message send" and slide the form up.
Anyway the main issue I am running into is that it submits the form but takes the user to the actual php file that it should of connected to via ajax. My code is as follows. It is probably something on the Jqmodal side of things but I am unsure if anyone could point me in the right direction that would be fantastic. Also close button is not working but I reckon I can fix that.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="http://www.modernizr.com/downloads/modernizr.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type='text/javascript'>
$(document).ready(function() {
$("#submit").click(function() {
var action = $("#contact_form").attr('action');
var form_data = {
code:$("#code").val(),
name:$("#name").val(),
email:$("#email").val(),
message:$("#message").val(),
is_ajax:1
};
$.ajax({
type:"POST",
url:action,
data:form_data,
success: function(response)
{
if(response == 'success')
$("#form").slideUp('slow', function() {
$("#message").html("<p class='success'>Your Message Has Been Sent.</p>");
});
else
$("#message").html("<p class='error'>Code was typed incorecctly.</p>");
}
});
return false;
});
// refresh captcha
$('#refresh').click(function() {
change_captcha();
});
function change_captcha(){
document.getElementById('captcha').src="./static/classes/get_captcha.php?rnd="+Math.random();
};
});
</script>
<link href="./static/css/style.css" rel="stylesheet" type="text/css" media="screen">
<link href='http://fonts.googleapis.com/css?family=Quantico:400,700' rel='stylesheet' type='text/css'>
</head>
<body>
<span id="close">
<button class="jqmClose">Close</button>
</span>
<br/><br/>
<form name="contact_form" method="POST" action="./static/classes/contact.php" enctype="application/x-www-form-urlencoded">
<input id="name" name="name" type="text" placeholder="Full Name..." required>
<br/>
<input id="email" name="email" type="email" placeholder="Your Email..." required>
<br/>
<input id="message" name="message" type="text" placeholder="Your Message..." required>
<br/>
<section id="captcha_area">
<img src="./static/classes/get_captcha.php" alt="" id="captcha" />
<br/>
<input name="code" type="text" id="code">
</section>
<section id="refresh">?</section>
<br clear="all" /><br clear="all" />
<input type="submit" id="submit" value="Send">
</form>
<span id="message"></span>
</body>
</html>
Change $("#submit").click(function() { to => $("#submit").click(function(e) {
e.preventDefault();. Rest of the code is same. This will stop default behavior of submit action.
OR you can use, .submit event.