ted_chou12 Posted June 23, 2009 Share Posted June 23, 2009 What if you have field name called delete or var? document.photocomment.delete.style.visibility = ... what can you do to prevent syntax? Thanks, Ted Quote Link to comment https://forums.phpfreaks.com/topic/163330-solved-if-you-have-specific-field-name/ Share on other sites More sharing options...
priti Posted June 23, 2009 Share Posted June 23, 2009 It's not a good practice to name variable like this if its a delete button then you should name it as - btnDelete if some Variable is there then it should be - varName do u get some error if you use document.photocomment.delete.style.visibility ... something like this ? Quote Link to comment https://forums.phpfreaks.com/topic/163330-solved-if-you-have-specific-field-name/#findComment-861760 Share on other sites More sharing options...
Adam Posted June 23, 2009 Share Posted June 23, 2009 It's not a good practice to name variable like this if its a delete button then you should name it as - btnDelete if some Variable is there then it should be - varName Hmm that's kinda what my Visual Basic tutor taught me at college, but to be honest I don't follow it. I find it a much bigger ball ache than it's worth; meaningful variable names should avoid any confusion. As for 'delete', I don't even think it's a prototype is it? What errors do you get? EDIT: I've found a 'delete operator'; but that uses a different syntax so shouldn't cause any problems... Quote Link to comment https://forums.phpfreaks.com/topic/163330-solved-if-you-have-specific-field-name/#findComment-861768 Share on other sites More sharing options...
ted_chou12 Posted June 23, 2009 Author Share Posted June 23, 2009 Hi, thanks for the advice, I am using this code in ajax, inserting this code in prevents the code to work, but im not exactly sure what the error is, can you let me know how to show the errors? Thanks, Ted Quote Link to comment https://forums.phpfreaks.com/topic/163330-solved-if-you-have-specific-field-name/#findComment-862010 Share on other sites More sharing options...
Adam Posted June 23, 2009 Share Posted June 23, 2009 If you're using FF it has a built in error console (tools > error console) - you should be able to find something to point you in the right direction there. If not perhaps look at installing Firebug or a similar FF extension. Quote Link to comment https://forums.phpfreaks.com/topic/163330-solved-if-you-have-specific-field-name/#findComment-862022 Share on other sites More sharing options...
Psycho Posted June 23, 2009 Share Posted June 23, 2009 Ok, I am in TOTAL agreement with those above - do not name elements "delete" or anything else that would cause a conflict. But, just for educational purposes, there is a workaround. document.photocomment['delete'].style.visibility = ... I only pose this because if you have fields named so they will be processed as arrays (i.e. name="foo[]") then you need to use this method to reference the fields. var fieldsArrayObj = document.formName['foo[]']; Quote Link to comment https://forums.phpfreaks.com/topic/163330-solved-if-you-have-specific-field-name/#findComment-862034 Share on other sites More sharing options...
ted_chou12 Posted June 24, 2009 Author Share Posted June 24, 2009 thanks, I changed the field name to "del", the code works after that Ted. Quote Link to comment https://forums.phpfreaks.com/topic/163330-solved-if-you-have-specific-field-name/#findComment-862753 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.