Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Thanked 0 Times in 0 Posts

    Javascript if statement not executing?

    Hello, I have the following function that is being called onClick from a button.

    function saveLocation(name, description, result, locationselect)
        var resultElement = document.getElementById(result);
        var nameText = document.getElementById(name).value;
        var descText = document.getElementById(description).value;
        var locationselectelement = document.getElementById(locationselect);
        new Ajax.Request("ajax.php?operation=savelocation&location="+nameText+"&description="+descText, 
                method: 'post', 
    	    onSuccess: function(transport)
    	        resultElement.innerHTML = "Successfully saved1.";
                   //refresh elements in pulldown
                   //find newly inserted element and select it
                   var i;
                   for(i = 0; i<locationselectelement.length; i++){
                   var OptionText = locationselectelement.options[i].innerHTML;
                       if(OptionText == nameText){
                          alert(OptionText+" was found when i="+i); 
                          locationselectelement.selectedIndex = i;
    Notice the
    line. If I un-comment this line, the code works and the if statement is executed, but if I leave it commented (which I need to in the end), the if statement is not being executed. I will also remove the alert that is inside the if statement when I am done.

    All of the variables are being initialized properly, because when I un-comment that line, the code works fine. Am I missing something?

    Thanks for your help in advance.
    Last edited by morbidfaith; 03-26-2009 at 09:13 PM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts