Jump to content

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

could you not just add what you did to start with to your Visibility function?

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.