Last Updated: February 25, 2016
·
670
· teknonono

persist dropdown menu values after submit

if you want to keep your drop down menu values after submitting, you can use javascript to persist these values.

document.getElementById('foo').value = "<?php echo htmlentities($_GET['foo'],  ENT_QUOTES);?>";

3 Responses
Add your response

This is open to XSS...

GET and POST vars should be escaped with htmlentities() as a minimum.

over 1 year ago ·

hi mattinahat99, thanks for your reminding!

over 1 year ago ·

This Javascript lib that does this as well. http://garlicjs.org/

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#javascript
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside