简体   繁体   中英

What's wrong with this “if” statement?

I have a big problem with jquery if condition: I have a div and if user click on it, calling ajax and user put a data and submit form. I check the input with jQuery and if it was OK send to another ajax form. for the first time it work and if check the conditions but for the second time if user click on div and call the first ajax then call the second ajax on submit jQuery if condition not work and send data to second ajax form even if condition was false!!!!

Note: if click on div every things work fine for the first time only and for the second time not. but if user refresh page after first submit and then click on div it works.

some part of my codes:

<div id="submit">submit</div>
//on click o div show the first ajax form for input
// and on submit check data and send it to second ajax
if( (val == 'A') || (val == '') ){
   //send data to ajax
} else if((cell_val != '') || (cell_val != 'A')){
   // show alert msg
}

I want to check if user input is something like "A" or empty then send data to ajax else show alert.

 if((cell_val != '') || (cell_val != '-')) 

would always return true

use

if (!(cell_val == '' || cell_val=='-'))

instead

In the first part of your code, your java script is inside of html. Use <script type='text/javascript'> your code `

In the second if after else you should use && instead of || . Just on the note - val and cell_val sound so similar that I wonder if this is what you wanted... I have this doubt also based on your explanation, for if I understood you well, you don't need to use anything after else except displaing alert box.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM