0

I am using jQuery to set the value of input box. If I assign the input id with $('#id').val(value) its working properly but I assign the variable then it doesn't work. please help.. my Sample code is

var box = '<?php echo addslashes($box); ?>';
function rowSelect(){
$('#'+box).val(selectedItem);
}
3
  • 1
    can u show the code that saves the selecteditem Commented Apr 3, 2014 at 5:59
  • What does the generated JavaScript code look like? Commented Apr 3, 2014 at 6:03
  • There's nothing wrong with the $('#'+box).val(selectedItem); line of code so the issue is either with the value of the variable box or the value of the variable selectedItem. You will have to show us the code that populates those variables for us to be able to help. Also, I'd suggest you look at the generated HTML (what the browser sees via View/Source in the browser) so you can remove any PHP echo issues from the equation and so we can see what the actual javascript is. Commented Apr 3, 2014 at 6:04

1 Answer 1

1

try it without single quotes because `php echo is considered it as string.

var box = <?php echo addslashes($box); ?>;    
function rowSelect(){
     $('#'+box).val(selectedItem);
}
Sign up to request clarification or add additional context in comments.

1 Comment

thanks sir.. the code is working for me... any other suggestion?

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.