Link to home
Start Free TrialLog in
Avatar of newbie27
newbie27Flag for United Kingdom of Great Britain and Northern Ireland

asked on

jQuery, comparing 2 strings

Hello Folks,
I am capturing SELECT element and Textbox values and I am trying to comparing it to check if they are equal like this

if($("#drpLists").val() == $("#txtListname").val()){
      $("#hiddflag").val('2');      
}

is this not correct?
please advice
thanks
s
      
SOLUTION
Avatar of Badotz
Badotz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KhoiNqq
KhoiNqq

Hi, I will needs your full source code to know what were wrong, your above code is okay, nothing wrong, I have the sample code, use it if you wish, or you can re-attach your code, I will analyze the problem for you.
<html>
<head>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js"></script>
<script type="text/javascript">
function compare()
{
  alert($("#drpLists").val());
  alert($("#txtInput").val());
  if ($("#drpLists").val() == $("#txtInput").val()){
    alert("Value equals");
  }else{
    alert("Value not equals");
  }
}
</script>
</head>
 
<body>
<select id="drpLists">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<input type="text" id="txtInput" value="3"/>
<input type="button" onclick="compare()" value="Compare" />
</body>
</html>

Open in new window

Avatar of newbie27

ASKER

Hello Guys,
Thanks for your comments, Please see my code attached hopefully you may get to see what I am trying to do here.
Just to give you an overview I am calling addToList() function , wanted to do some validations and based on them passing appropriate flag values ($("#hiddflag").val('2')) to the proxy page to process by calling submitForm() function.

but it is not passing appropriate hidden values in the ajax call.

Thanks for looking.

Regards
Sam

function addToList()
{
  if($("#drpLists").val() == 0){
    alert('Please select a list');  
  }else if($("#drpLists").val() == "new" && $("#txtListName").val() == ""){
    alert('Please enter List Name');
  }else{
	
if($("#drpLists").val() == "new" && $("#txtListName").val() != ""){
		$("#hiddflag").val('0');	
}else if($("#drpLists").val() != "new" && $("#txtListName").val() == ""){
		$("#hiddflag").val('1');	
	}else if($("#drpLists").val() == $("#txtListName").val()){
		$("#hiddflag").val('2');	
	}
	
    var result = "";             
    $(".chkRefNos").each( function () 
        {
        if(this.checked == true) {     
             result += "," + $(this).val()  ;
        }
        });
        result = result.substr(1);
            if( result ){
				
					 					  					 
					  submitForm('frmList', 'savefields');
					
            } else{
				checkAll("on");
				submitForm('frmList', 'savefields'); 	
			} 
  }
 //return false;   
} 
  
 
 function submitForm(frm, ax){
// requires jquery 
        $('#action').val(ax);
        var myForm = $("#" + frm);
                var param="";
                $(".edit_area").each( function(){param+= "," + escape(this.innerHTML) });
                param = "itemNotes=" + param.substring(1);
 
        var frmParams = myForm.serialize() + "&" + param;
         
                $.ajax({
                 type: "POST",
                url: "list_save_proxy.asp", 
                dataType: "xml",
                data: frmParams,
                success: function(xml){
                                
                                var errCode = $("errorcode", xml).text();
                                var errMsg = $("errormsg", xml).text();
                                var resTxt = $("responsetext", xml).text();
                                
                                if(errCode == 0){
											if(resTxt =="exist"){
											  if(confirm('List Name Already exist, Do you want to over write it?')){
												   submitForm('frmList', 'savefields');  
												   $("#hiddflag").val('4');
												}
											 }else{                                
												$('#responsemsg').html(resTxt);
												repopulateList();
											}	
								}else{
                                        $('#responsemsg').html('\n<br> > ' + resTxt + '');
                                        $('#responsemsg').append(' [' + errCode + ' ' +  errMsg + ']'); 
                                }
                            }  
        });
        }

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeah you are right I actually have not set the hiddFlag value in the HTML correctly but it is now seems to be working ....!!

However, I am now facing problems in displaying correct data in the Flexigrid. All I am doing there is to pick the name from <SELECT> and when I click on View list button I am doing an Ajax call to show details of selected option in the Grid.
But it is not doing it right.
Can you please have a look it here

https://www.experts-exchange.com/questions/23471788/jquery-flexigrid-not-getting-updated-on-onClick-event.html

thanks for your help
sam
thanks
No worries - glad to help.