freelance84 Posted October 13, 2010 Share Posted October 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/215775-hiding-and-focusing-with-one-click/ Share on other sites More sharing options...
Zane Posted October 13, 2010 Share Posted October 13, 2010 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() } Quote Link to comment https://forums.phpfreaks.com/topic/215775-hiding-and-focusing-with-one-click/#findComment-1121743 Share on other sites More sharing options...
freelance84 Posted October 13, 2010 Author Share Posted October 13, 2010 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');" Quote Link to comment https://forums.phpfreaks.com/topic/215775-hiding-and-focusing-with-one-click/#findComment-1121747 Share on other sites More sharing options...
Zane Posted October 13, 2010 Share Posted October 13, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/215775-hiding-and-focusing-with-one-click/#findComment-1121749 Share on other sites More sharing options...
freelance84 Posted October 13, 2010 Author Share Posted October 13, 2010 Yea, but i'm also trying get a better grasp on JS. This way i can use the function on other pages too thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/215775-hiding-and-focusing-with-one-click/#findComment-1121751 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.