0

I'm trying to load some content via Ajax and fancybox, I have a problem establishing a validation before fetching the content. I'm trying to check if the array has some value first, and does not equal the default first dropdown option, then proceed.

My first element of the dropdown is the Select Object with a value Object, but for example if I select X, content will load, then if I select Object, the validation is not working, and content for the last selection is loading.

HTML

<select  id="sat" onChange="get_bm(this.value)">
<option value="Object" selected="selected">Object Name</option>
<option value="X" selected="selected">X</option>
<option value="Y" selected="selected">Y</option>
</select>

<input name="Btn" class="toolsMenu channel fancybox.ajax" href="content.php"  onclick="get_info()"/>

Javascript

function get_info(){


var Satquery = new Array();  //create Array with two dropdown selections
var bm = document.getElementById("bm").value; //Get Dropdown1 value
var sat = document.getElementById("sat").value;  // Get Dropdown2 value
Satquery [0] = bm;
Satquery [1] = sat;


if (Satquery[1] !== 'Object' || Satquery[0] !== null ){    //Here some validation that its not empty and does not equal the default selection option


  $(".channel").fancybox({
    ajax : {
        type : "POST",
        data : "Sat="+Satquery
    },
        fitToView   : true,
    autoDimensions : true,
    closeClick  : false,
    openEffect  : 'none',
    closeEffect : 'none'
});

  }

Satquery =[]; /// Here Im trying to empty the array after each click because if I select again 'Select object' with value 'Object' the validation is not working and content for last selected item is being loaded..
  }
1
  • yes, sorry thomas typing mistake Commented Dec 7, 2013 at 12:49

1 Answer 1

1

Replace "OR" with "AND".

Change

if (Satquery[1] !== 'Object' || Satquery[0] !== null )

to

if (Satquery[1] !== 'Object' && Satquery[0] !== null )

or even

if (Satquery[1] !== 'Object' && Satquery[0])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.