How to register a style for js element?

Hello! Please help in the following...
59d925d71757f313566185.png
June 14th 19 at 19:07
2 answers
June 14th 19 at 19:09
Abrite window.onload = function ... and leave only $(document).ready
Please tell me how to write it?
I need:
if(if the name field with email value == ""){
assign the field border(and better outline) to 1px solid #ff0000;
} - pearl_McCullough commented on June 14th 19 at 19:12
,
if(document.getElementById("email").value == "")
 document.getElementById("email").style.outline = "1px solid red";
- Alene56 commented on June 14th 19 at 19:15
June 14th 19 at 19:11
you're kind of jq is connected, what for these designs???
if($('#mail').css( "outline" )=='red'){
 return false;
}

and so on... open Google and type in 5 words, can it be so lazy?
PS: Actually it seems that you there is something absolutely wild figachit, the type of validation the field by the color of the elements...
I'm not good as you! I'm not lazy, I just don't know what to drive! Think I want to go to the forum? There is always some wise guy who wants to be sarcastic. And that's half the trouble! Worse, when simply quip and will not leave no response! But back to the question.... You did not understand me, I will try to explain differently!
I need:
if(if the name field with email value == ""){
assign the field border(and better outline) to 1px solid #ff0000;
}
<div class="contact">
 <div class="wrapper">
 <div class="contact-title" id="about">subscribe now and get a free consultation!</div>
 <form id="former" method="post">
 <input type="text" placeholder="Your name" id="name" name="name" value="<?=$_POST['name']?>">
 <p class="err n" style="color:red"><?=$err['name']?></p>
 <input type="email" placeholder="Your email" id="email" name="email" value="<?=$_POST['email']?>">
 <p class="err e" style="color:red"><?=$err['email']?></p>
 <input type="text" placeholder="Your Skype" name="skype" value="<?=$_POST['skype']?>">
 <textarea name="sms" cols="30" rows="10" placeholder="message" value="<?=$_POST['sms']?>"></textarea>

the <div>
 <button>Send request</button>
</div>
</form>
</div>
 </div>
- pearl_McCullough commented on June 14th 19 at 19:14
so much better and easier to understand, better explain, and then the picture and "not working!" is not a question.
Something like this should be:
$(document).ready(function () {
 $('#former').on('submit', function(e){
e.preventDefault();
 var sub = true;
 if($('#name').val()==""){$('#name').css( "outline","red" ); sub=false;}
 if($('#email').val()==""){$('#email').css( "outline","red" ); sub=false;}
if(sub)$('#former').submit();
})
})

I think what you need about - Alene56 commented on June 14th 19 at 19:17
,
I'm not lazy, I just don't know what to drive!

"hide element in jquery"
"set the item style jquery"
"check empty input jquery"

Reference queries in the Google buy in kiosks Sojuzpechat! - pearl_McCullough commented on June 14th 19 at 19:20
unfortunately not working... I tried two options!
First
$(document).ready(function() {
 $( document ).on('submit', 'form', function(event) {
event.preventDefault();

 if($('#name').val()==""){$('#name').css( "outline","red" ); valid = false; return valid;}
 if($('#email').val()==""){$('#email').css( "outline","red" ); valid = false; return valid;}

$.ajax({
 type: "POST",
 url: "form.php",
 data: $(this).serialize()
 }).done(function() { 
alert('Thanks');
});
 return false;
});
 });

The second (yours)
$(document).ready(function () {
 $('#former').on('submit', function(e){
e.preventDefault();
 var sub = true;
 if($('#name').val()==""){$('#name').css( "outline","red" ); sub=false;}
 if($('#email').val()==""){$('#email').css( "outline","red" ); sub=false;}
if(sub)$('#former').submit();
})
})
- lily.Kozey commented on June 14th 19 at 19:23
learn to give a little more informative answers than "not working". Scripts can output to the console error(SEE CONSOLE IN the FIRST PLACE!!!!).
If you need anything to check progress - there is a console.log(var); - lily.Kozey commented on June 14th 19 at 19:26
No error console does not give!
My version: When empty fields, clicking the button displays the alert. That is, the condition passes without throwing border
$(document).ready(function() {
 $( document ).on('submit', 'form', function(event) {
event.preventDefault();

 if($('#name').val()==""){$('#name').css( "outline","red" ); valid = false; return valid;}
 if($('#email').val()==""){$('#email').css( "outline","red" ); valid = false; return valid;}

$.ajax({
 type: "POST",
 url: "form.php",
 data: $(this).serialize()
 }).done(function() { 
alert('Thanks');
});
 return false;
});
 });

Your option: When you press the button, with the same blank fields, the fields, the page is reloaded! And this is a mistake! This should not be at all!
$(document).ready(function () {
 $('#form').on('submit', function(e){
e.preventDefault();
 var sub = true;
 if($('#name').val()==""){$('#name').css( "outline","red" ); sub=false;}
 if($('#email').val()==""){$('#email').css( "outline","red" ); sub=false;}
if(sub)$('#form').submit();
$.ajax({
 type: "POST",
 url: "form.php",
 data: $(this).serialize()
 }).done(function() {
alert('Thanks');
});
 return false;
});
});
- pearl_McCullough commented on June 14th 19 at 19:29
the page is reloaded! And this is a mistake! This should not be at all!
easy, I wrote the example code, wrote a project for you that there should be - recognize submit or Ajax - not the point. you don't think like a programmer, yet you kopipaster. Change your view of things, instead of "what the *!*I it doesn't work" should be "why not work where did I go wrong? I'll check what it is and how varied and it will work".
I wrote - have console.log(), use, and check what and where is displayed. For example:
$(document).ready(function () {
console.log('Document is loaded, make the magic');
 $('#former').on('submit', function(e){
e.preventDefault();
 var sub = true;
 console.log($('#name')); // see whether there is such an element, or not at all
 console.log($('#name').val()); // see whether there is in the valuy 
 //element, maybe a space or newline
 if($('#name').val()==""){$('#name').css( "outline","red" ); sub=false;}
 if($('#email').val()==""){$('#email').css( "outline","red" ); sub=false;}
 // if(sub)$('#form').submit(); // not tupim, remove recognize submit form if you do not need
if(sub){
$.ajax({
 type: "POST",
 url: "form.php",
 data: $(this).serialize()
 }).done(function(data) { //data will return the server's response, for example, you can display errors
 console.log(data); // see what was sent to the server, most likely nonsense, but why should...
alert('Thanks');
$('#former').hide();
});
}
 return false;
});
});


And now in the console, the full balance of what you have going on in the function. - lily.Kozey commented on June 14th 19 at 19:32
all that gave...
59d9500bbb1c6917857861.png
Please take a look at the code: https://yadi.sk/d/GsntnfvA3NZKDs - pearl_McCullough commented on June 14th 19 at 19:35
https://yadi.sk/d/wI_X08Bp3NZLGm and there's also code at all close does not lie with what you wrote here! - lily.Kozey commented on June 14th 19 at 19:38
THANK YOU SO MUCH!!!! I just can not understand... How to remove? And why is this? It appears after fires alert('Thanks!');
And why do we need another file - jquery.min,js? And as you realized he need?
59d96454d2212947915000.png
And please tell me what books you can recommend? How did you learn?
PS Code is different because I specifically removed all the excess so that you can show! - pearl_McCullough commented on June 14th 19 at 19:41
And please tell me what books you can recommend? How did you learn?
Docks. Almost everyone today have some documentation and almost all of the tutorials.
Actually I graduated applied mathematics at the state University, then just take a new language, understand the syntax and wrote on it something. The main thing to understand that you want to get a result, and what steps you need to do, then we can solve the problem in steps, if the language is new for you - Google just necessary(kick as I do without the Internet before kodil...), and in the "native" language is sometimes naryvaeshsya on obscure problems that only Google / toaster / to solve possible.
How to undo it?

in the index, clear the block
<div class="popupcontacttitle" id="about">subscribe now and get a free consultation!</div>
- lily.Kozey commented on June 14th 19 at 19:44
, Applied mathematics! And I was hoping you ordinary people)) Well, now I understand how you have so cleverly turns) ... have any questions. Last...
I can't remove the unit as this part of the site. Besides, except this unit is connected overlay(dark background) And pressing the button on the page 'Send request' appears not a modal window with the form, and the same element
<div class="popupcontacttitle" id="about">subscribe now and get a free consultation!</div>

I believe that as the decision can be redirect to the same page after alert('Thanks'); Only it must not be the type of header('Location: /otzivi.php'); but something like... header('Location: /the same page(without specifying the name like action="").php'); I tried to get rid of them with these lines
$('#about').css( "display"," none" );
$('.pop').css( "display"," none" );
$('.overlay').css( "display"," none" );

but I just hid them... When re-calling the form from a modal window, nothing happens. So, I need the code restarting the browser after an alert. ... I wonder why....
I found online and used, instead of 3 lines, with the following code:
location.reload();
after alert(); And turned out) the Only thing I want to check is whether I could send by POST the filled fields. I just don't see it here. Not used before so the console is like these days. Tell me... I saw only this:
59d97b7e42712720921979.png59d97c7dd074d555487626.png59d97b8b83e94256231736.png
Second... I can not understand why there are errors on empty fields, which are set out in form.php I can't test whether the function of sending mail because they are on local... - pearl_McCullough commented on June 14th 19 at 19:47
,
So, I need the code restarting the browser after an alert
Generally it is a bad idea, but if you really want, here: location.reload

I want to check is whether I could send by POST the filled fields.
See what is in the request body.
zjIwexm.png
I can not understand why there are errors on empty fields, which are set out
there is a word "debugging". And there are cool things like debuggers. Browser debugger you have already started to use it, php is also nothing really terrible.
lyVHAiX.png
does generally function to send mail because they are on local...
You can put a plug which will just add letters to daddy. - lily.Kozey commented on June 14th 19 at 19:50

Find more questions by tags AJAXJavaScript