vytas Posted March 17, 2007 Share Posted March 17, 2007 Ok i have this code: <script type="text/javascript">function move(){document.getElementById('object').style.position="absolute";document.getElementById('object').style.left="400";var xpos = document.getElementById('object').style.left;var CMD = document.getElementById('object').value;if(CMD = 'right'){document.getElementById('object').style.left=xpos - 10;}}</script> I whas trying to move the object if the value of the textbox whas right.But i get a error saying invalid argument , it is most likely because xpos = 400px .But how do i solve that? Link to comment Share on other sites More sharing options...
Andrew K. Posted March 18, 2007 Share Posted March 18, 2007 Try changing document.getElementById('object').style.left="400"; to document.getElementById('object').style.left="400px"; I dunno if it will work, but it should. Link to comment Share on other sites More sharing options...
jesh Posted March 19, 2007 Share Posted March 19, 2007 var xpos = document.getElementById('object').style.left;...document.getElementById('object').style.left=xpos - 10; Yeah, I think the problem is because you are trying to subtract 10 from "400px". Try using offsetLeft rather than style.left to get the position.var xpos = document.getElementById('object').offsetLeft;...document.getElementById('object').style.left = (xpos - 10) + "px"; Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now