anth0ny Posted December 18, 2008 Share Posted December 18, 2008 Hi everyone, I have been searching around the net but couldnt find an answer to this. How would i validate this form field that uses the value field for onfocus and onblur? Its not empty as it has 'i.e ITA001' in the field. I need something that says, if 'i.e ITA001' show error type of thing <input name="customerRef" type="text" class="fields" id="customerRefField" onfocus="if (value='i.e ITA001') {value=''}" onblur="if (value=='') {value='i.e ITA001'}" value="i.e ITA001" size="25" /> thanks for your help everyone Quote Link to comment https://forums.phpfreaks.com/topic/137535-solved-form-validation/ Share on other sites More sharing options...
Adam Posted December 18, 2008 Share Posted December 18, 2008 I've posted a solution in the other topic that got moved! A Quote Link to comment https://forums.phpfreaks.com/topic/137535-solved-form-validation/#findComment-718757 Share on other sites More sharing options...
Maq Posted December 18, 2008 Share Posted December 18, 2008 Please double posting is a waste of time. Won't get you anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/137535-solved-form-validation/#findComment-718768 Share on other sites More sharing options...
anth0ny Posted December 18, 2008 Author Share Posted December 18, 2008 was an accident, put it in the php forum first as thought there could be a php solution, was told to put it in the javascript forum, so did. Then this one got moved? Sorry for it looking spammy, still need some help though if you have an solution cheers Quote Link to comment https://forums.phpfreaks.com/topic/137535-solved-form-validation/#findComment-718780 Share on other sites More sharing options...
Maq Posted December 18, 2008 Share Posted December 18, 2008 was an accident, put it in the php forum first as thought there could be a php solution, was told to put it in the javascript forum, so did. Then this one got moved? It's OK. People probably told you to move it when they should have reported it for moderators to move. Anyway, MrAdam's solution didn't work? I've posted a solution in the other topic that got moved! A Quote Link to comment https://forums.phpfreaks.com/topic/137535-solved-form-validation/#findComment-718791 Share on other sites More sharing options...
anth0ny Posted December 18, 2008 Author Share Posted December 18, 2008 Its throwing up an error: object expected Quote Link to comment https://forums.phpfreaks.com/topic/137535-solved-form-validation/#findComment-718803 Share on other sites More sharing options...
Maq Posted December 18, 2008 Share Posted December 18, 2008 First of all you need to use the comparison operator not assignment on this line: onfocus="if (value='i.e ITA001') Change to: onfocus="if (value=='i.e ITA001') Quote Link to comment https://forums.phpfreaks.com/topic/137535-solved-form-validation/#findComment-718812 Share on other sites More sharing options...
anth0ny Posted December 18, 2008 Author Share Posted December 18, 2008 so far i have this <script type="text/javascript"> <!-- function defaultValSwitch(obj, default, e) { var val; if (e == 'onfocus') { val = (obj.value == default) ? '' : obj.value; } else { val = (obj.value == '') ? default : obj.value; } obj.value = val; return; } //--> </script> <input name="customerRef" type="text" class="fields" id="customerRefField" onfocus="defaultValSwitch(this, 'i.e ITA001', 'onfocus');" onblur="defaultValSwitch(this, 'i.e ITA001', 'onblur');" value="i.e ITA001" size="25" /> but its throwing up: error: expected identifier? Quote Link to comment https://forums.phpfreaks.com/topic/137535-solved-form-validation/#findComment-718832 Share on other sites More sharing options...
Maq Posted December 18, 2008 Share Posted December 18, 2008 Can you show me the whole code? That portion works fine for me. Quote Link to comment https://forums.phpfreaks.com/topic/137535-solved-form-validation/#findComment-718860 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.