javascript - How to make the select option tag fill the action attribute with an url so it can open that website -
i need option value fill in action attribute in form can open website. code doesn't work. missing complete process?
<form action=" " name="test"> <select name="url"> <option value="google">google</option> <option value="yahoo">yahoo</option> </select> <input type="submit"/> </form> <script> $("form").submit(function () { var selectval = $('select').value(); var url = ''; if(selectval == "google") url = 'http://www.google.com'; else if(selectval == "yahoo") url = 'http://www.yahoo.com'; if(url != ''){ window.open(url, '_blank'); } }); </script>
i need option value fill in action attribute in form can open website. code doesn't work. missing complete process?
<form action=""> <select name="url"> <option value="https://www.google.com">google</option> <option value="https://www.yahoo.com">yahoo</option> </select> <input type="submit"/> </form> <script> function setdata(){ var select = document.getelementbyid('url'); var test_id = select.options[select.selectedindex].value; document.form.action = test_id; form.submit(); } </script>
Comments
Post a Comment