vbnullchar Posted June 12, 2007 Share Posted June 12, 2007 how will i know i know if an elementID already exist? Link to comment https://forums.phpfreaks.com/topic/55236-div-problem-double-post-sorry-resolving/ Share on other sites More sharing options...
nogray Posted June 12, 2007 Share Posted June 12, 2007 Well, you can use a "try and catch" statment. It's not a perfect solution but it works. <script language="javascript"> function checkID(){ try { var objID = document.getElementById(document.getElementById('input1').value).id; alert("ID is already in use"); return true; } catch(e){ alert("There is no object with this ID"); return false; } } </script> <div id="div1">First Div</div> <input type="text" id="input1" value="div1" /> <button onclick="checkID();">Check if ID</button> Link to comment https://forums.phpfreaks.com/topic/55236-div-problem-double-post-sorry-resolving/#findComment-273271 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.