Jump to content

hiding and focusing with one click


freelance84

Recommended Posts

if (document.edit_name)
{
document.edit_name.forename.focus()
}

This puts the cursor into the textbox named forename if it exists

 

 

function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
}

This when applied with:

onclick="setVisibility('name_instructions', 'none');"

Will hide a <div> named name_instructions when clicked on.

 

 

What i am now aiming to do is:

When the user clicks on the div, it hides the div but then also focuses on the textbox named forename within the edit_name form.

 

How would i add this function to the setVisibility function?

 

Could i give the text box in question an id then add the following to it:

document.getElementById(id).focus()

 

 

Any help or pointer to relavent help would be brilliant, JS is still very new to me so as usual searching the correct keywords isn't very easy when looking for help on google.

Link to comment
https://forums.phpfreaks.com/topic/215775-hiding-and-focusing-with-one-click/
Share on other sites

function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
document.edit_name.forename.focus()
}

 

.... i think the pennies just dropped.

 

Would this work:

function setVisibility(id, visibility,id2) {
document.getElementById(id).style.display = visibility;
document.getElementById(id2).focus()
}

with:

onclick="setVisibility('name_instructions', 'none', 'forename');"

That would only work if you had an element with an ID of 'forename'

 

Unfortunately, you are using forename as a name for an element.  Although, you can still give that element an ID of forename manually and it will work, why can't you use what I suggested?  You said yourself in your OP that it put the cursor in the correct place

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.