Hiding then focussing on select element underneath - javascript

I have a div which hides a select box. When a user clicks on the div it disappears and shows the select box. Then when the user clicks away from the select i want the div to show again and essentially cover it up.
so, to hide the div I have the following:
onclick="document.getElementById(\'infoi'.$div_i.'\').style.display = \'none\';"
When the user has touched the select and clicks away I have the following which covers the select again:
<select name="g_name" onchange="this.form.submit();" onblur="document.getElementById(\'infoi'.$div_i.'\').style.display = \'block\';" style=width:170px;>
for this to work as i want it to though, the user has to actually click the select, even without selecting anything, for it to gain focus and therefore the onblur will turn the div back on.
So, I try the following to hide the div and set the focus on the select:
onclick="document.getElementById(\'infoi'.$div_i.'\').style.display = \'none\'; document.getElementById(\'g_name\').focus();"
Bit it simply does not work, any ideas?

I have a working example of what I think you are after here http://jsfiddle.net/Znct3/10/
looking at your code you were applying focus to an element with an ID of g_name but your select only has a name of g_name

Related

Unselect the select box once isClearable is clicked or true

I wanted to unselect the Input box once the close button is selected after the option is selected
I have attached codesandbox link
Current output
When user select the option value is displayed when close icon is clicked it removes the option but select box is selected unless you click outside, it un-selects the box
expected output
When user select the option value is displayed when close icon is clicked it removes the option and un-selects the box as well.
You are talking about something named 'focus'.
This is actually built-in browser behavior, so if you want it to lose focus in some cases you can do it programmatically using refs.
Here is a link to guide where you can find how to do it

Can't click or select an item from javascript dropdown menu using VBA

As the title suggests, I've found the ClassName of the button I want to click (I think, because the innertext on that ClassName array # gives me the correct text shown on button). Problem is, I'm clicking it but it does nothing.
This is my best attempt, among dozens, but it's not doing anything.
For Each i In IE.document.getElementById("typeSelector")
If i.innerText = "Revenue" Then
i.Click
i.FireEvent ("onchange")
'This click and fireEvent are activated but do nothing.
End If
Next i
'These next ones are Hail Mary's stacked on top of each other to see if I get a reaction out of that damn box. Nada.
Debug.Print IE.document.getElementsByClassName("chzn-single chzn-default")(0).innerText 'Prints "Select an option". I thought clicking this would at least open the drop down menu but still, nothing.
Debug.Print IE.document.getElementById("typeSelector_chzn_o_14").innerText 'Prints "Revenue". This is the option within the dropdown menu, shown after clicking the menu when manually done.
IE.document.getElementsByClassName("chzn-single chzn-default")(0).Click
IE.document.getElementById("typeSelector_chzn_o_14").Click
To summarize, I've tried activating the option based on index, clicking the box, clicking the box then clicking the "Revenue" option. The website remains completely unmoved. Should be noted that a succesful click would not update the website, simply highlight the "Revenue" option in the menu, and open up a Date input box.

Jquery: Change select box value and and activate a click state

So whats going on is that I have a site that I have taken on for my work. I have two select boxes I am tying into. The problem is when you click the second select box and choose an option it uses ajax to load a second box next to it (a hierarchical select box). The code that I am using is simple and changes the value of the second box back to the "select" option state when the first box is changed. But what it is not doing is creating click state (sorry if I am saying that wrong) but in order for ajax to bring in and remove the third select box the second select box option needs to be clicked.
Is there a way for me to re-create a "click" of the select box.
Here is the jquery:
$(".state.form-select").change(function() {
$('.hierarchical-select .form-select').val('select');
});
Here is a sample fiddle. See this Fiddle
I am not entirely sure, what exactly you are looking for but I feel that this should do the trick:
https://jsfiddle.net/vuvckm3u/5/
$(".state.form-select").change(function() {
$('.hierarchical-select .form-select option:first-child').attr('selected', true);
});

click button simulates clicking a dropdown hidden

I do not know if it's possible, but wanted to have a jsp page when loaded uam dropdown does not appear, but when I click a button.
Basically I want a button that makes the select box. that when clicked appear a list "option".
Already experimenting with various js events and jquery but none works. I had a div with style = "display: none;" and within the div I have the select. and wanted to show the option only when you click a button. It is possible ?
Thanks for listening
try this
$(document).ready(function(){
$('.mySelectbox').hide();
$('.myButton').click(function(){
$('.mySelectbox').val(-1); //clear selection of selectbox
$('.mySelectbox').show(); //show make the magic
});
});
this work for you?

Use up/down arrows to scroll select list but keep focus on input element

I want user to be able to scroll through select options with up/down arrows, but be able to press ctrl-c to copy from a matching input element whenever they want, seamlessly.
But I'm having trouble juggling the focus.
The best I've gotten is it works but I have to press down twice to move to the next select element.
Here is a fiddle I created, which isn't even populating the select box for some reason. Though it works on my server. On my server the picsarray array is generated with PHP, but it should be the same effect as here.
https://jsfiddle.net/bbmqy0xm/2/
You can leave focus alone and just call select() to highlight the text after you set it:
function showpicture(selectobj) {
/* deleted irrelevant js */
$("#image_name").val($(selectobj).val()).select();
}
https://jsfiddle.net/s4rmytt5/

Categories