This article shows how to get selected value from dropdown box when a button is clicked.
– There are multiple forms in a page.
– There is a dropdown select box in each form.
– The option value of the select box is website URL.
– There is a button type=button (not type=submit) in each form.
– User will select a value from the select box and click the button.
– I need to get the selected option value (which is website URL) and open the URL in new window.
This might be simple one but it is a very handy code. Generally, I see this being used in Search textbox where there is some text like ‘search…’ by default. And, when you put the mouse cursor on the textbox, the text is removed and then you can type your desired search text.
var current_url = location.href;
Here is another way:-
It is very easy to execute some code after a specified time-interval, i.e. setting some time interval between the code. We can use the setTimeout function.
Here is the code:
I have called showHideDiv() Js function when the link is clicked. The display of the div where content is present, is visible or hidden on each click. For this, CSS styling is used (display: none).
In my html elements, I have created ‘li’ and ‘strong’ elements inside ‘div’. The div id is ‘summary’. I have written comment in the code so that it would be easy to understand.