Genesis5150 Posted July 4, 2015 Share Posted July 4, 2015 I'm looking for a solution for the javascript version of if isset in php. This is what I have: if (typeof obj.office !='') {( document.listingform.office.value.length < 3 ); { if (valid) document.listingform.office.focus(); document.listingform.office.style.border="solid 1px red"; msg+="\"Office\" field cannot contain less than three characters\n"; valid = false; } } What I want to to do is if the field "office" holds a value and is less than three characters then alert but only if it has a value. How can I do that. Link to comment https://forums.phpfreaks.com/topic/297174-if-isset-javascript-equivalent/ Share on other sites More sharing options...
requinix Posted July 4, 2015 Share Posted July 4, 2015 "isset" isn't the thing you're looking for, then. Because the thing exists. Just check for an empty value. Link to comment https://forums.phpfreaks.com/topic/297174-if-isset-javascript-equivalent/#findComment-1515580 Share on other sites More sharing options...
Genesis5150 Posted July 4, 2015 Author Share Posted July 4, 2015 Thanks for the advice I went on and tried this but no luck: if (obj.office && obj.office.length < 3) { if (valid) document.listingform.office.focus(); document.listingform.office.style.border="solid 1px red"; msg+="\"Office\" field cannot contain less than three characters\n"; valid = false; } Link to comment https://forums.phpfreaks.com/topic/297174-if-isset-javascript-equivalent/#findComment-1515585 Share on other sites More sharing options...
requinix Posted July 5, 2015 Share Posted July 5, 2015 I don't know where valid or obj.office are coming from, but what I meant was a simple document.listingform.office.value == "" Link to comment https://forums.phpfreaks.com/topic/297174-if-isset-javascript-equivalent/#findComment-1515590 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.