jQuery select list set selected using php variable

Using jQuery to set the selected element of the select control to be the item with the text description. Value from php.

	//set js var from php var
	var myText = '<?php echo $myText; ?>';
	//set selected using text value
	//$("#my-Select option[ text=" + myText + "]").attr("selected","selected") ;
	//set selected using value value
	$("#my-Select option[value=" + myText +"]").attr("selected","selected") ;

By Keenlio, August 6, 2014

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

one + 5 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>