Skip to main content
avid_body16B8
Legend
December 4, 2019
Question

how to get focus on a button in ANCC HTML5

  • December 4, 2019
  • 2 replies
  • 1189 views

I have 6 input texts and a submit button set on visible =  false.

When all 6 input texts are filled in the submit button has visible  =  true. This works fine but I want the button then to get the focus. I can get focus on the input text but I am not sure how to do it with the submit button.

function checkIfDone() {	
	if (result1.length != 0 && result2.length != 0 && result3.length != 0 && result4.length != 0 && result5.length != 0 && result6.length != 0) {
		root.submitBtn3.visible = true;
	} else {
		root.submitBtn3.visible = false;
	}
}

 

Each input has this code:

function A_change(evt) {
	result1 = [];
	result1.push(evt.target.value);
        // move to next imput field
	$("#B").select();
}
// get value
$("#dom_overlay_container").on("change", "#A", A_change.bind(this));
// get submit if all input fields are filled in
$("#dom_overlay_container").on("keyup", "#A", checkIfDone.bind(this));

 

This topic has been closed for replies.

2 replies

JoãoCésar17023019
Community Expert
Community Expert
December 4, 2019

Hi, res.

 

Yeah. I also agree that there isn't this concept of focus in CreateJS objects.

 

But if you already using DOM inputs, maybe you could also use a DOM button too. Then you're gonna be able to set the focus, I guess.

 

 

Regards,

JC

avid_body16B8
Legend
December 4, 2019

Good idea JC, in general but I am assigned art at work and I cannot change it. I might be able to copy it with CSS tho and definitely worth the try.

Legend
December 4, 2019

If the objective is just to submit when Enter is pressed, that's not hard.

var _this = this;

this.submitButton.addEventListener("click", submitClicked);
function submitClicked(evt) {
	evt.remove();
	window.removeEventListener("keydown", keyPressed);
	alert("CLICKED!");
}

window.addEventListener("keydown", keyPressed);
function keyPressed(evt) {
	if (evt.key.toLowerCase() === "enter") {
		_this.submitButton.dispatchEvent(new createjs.Event("click"));
	}
}

 

Legend
December 4, 2019

To the best of my knowledge, CreateJS objects do not have the concept of focus.

avid_body16B8
Legend
December 4, 2019

Well, that's too bad. I guess I will try and find some way around.