I have made a script, but it’s not working as expected, and I need help. You can see it here.
I need to implement the following behavior for the URL field only:
- When you click on the link, the target page opens. This works.
- When you click on the link’s parent
div, the link becomes an editableinput. This also happens, but my input field’sidis taken from an array, e.g. (url0,url1,url2), so when I have more than one URL in the form, only the first one works. - When you click outside after editing the input, it becomes a link again.
- Also, when you double click on the link, it becomes editable.
Thanks in advance for all the answers, and I hope you can help me with this.
You can’t use the same
idfоr different page elements – this is invalid markup, and, as you can clearly see, leads to invalid behavior. First things first, you might want to fix that in your markup.If you can’t change that (but, once again, you really should!), you can use some more involved selectors, for example:
Pretty silly, huh? You can probably use this mess as your last resort, though.
As for double clicking, I wouldn’t recommend implementing such behavior; it is uncommon in a Web context, and might be confusing to users. Also, from a technical standpoint, a single click already starts to load the new page; you could use
window.stop()to stop that if the link is double clicked, but you’ll need to manually implement a double click event, since:I think you should just have a small “edit” button to the right (maybe a “pencil” icon?), instead of going with your current UI scheme. It seems quite confusing to me – not to mention the users…