I am trying to pass value of xyz from function to a new var abc, but its not working. I tried like abc="'"+xyz+"'"; (Not working) If I try like abc='anything'; it works and i can use abc value to new function in document.ready function. I want dynamically generated value of xyz, for abc with single quotes. With all your suggestion I am updating the code, i tried all the way... but dont know why abc is not catching the value of xyz or newcityval(); Also I have one line script above the code, where default value of abc is specified. Now when city value changes city_val gets updated and same i check using alert function. Also for abc if i put any value manually like abc='anything'; and alert it work fine. But using all the suggesstions its not working. I also declared global vars for both xyz and abc. updated code
<script type='text/javascript'>abc = 'any value';</script>
<script type='text/javascript'>
var xyz;
var abc;
function newcityval(){
xyz = $("#city").val();
document.getElementById('city_val').value=xyz;
return alert("'"+xyz+"'");
}
abc=newcityval();
if(abc!='')
{
alert("value is "+abc);
}
else
{
alert('No value');
}
</script>
Thanks
var abc = newcityval()?abc="'"+xyz+"'";isn't working becausexyzhasn't been declared in that scope. Try:abc=newcityval();I'm guessing that is more what you want.