El_Dudereno Posted August 19, 2009 Share Posted August 19, 2009 I have a text box which is to be used to take an input from a user for a bank sort code. This is shown below <body> <form> <p>The layout used in this input is three pairs of numbers seperated by -. Thanks for taking the time to read this!</p> <p><input type="text" name="Bank_Sort_Code" id="Bank_Sort_Code" onblur="validateBankSortCode($Bank_Sort_Code)" /> (Bank Sort Code)</p>//Function to validate Bank Sort Code Text Box </form> I have the textbox calling a function on blur which is stated below: <?php function validateBankSortCode($Bank_Sort_Code) { if(ereg('^[0-9]{2}-[0-9]{2}-[0-9]{2}$', $Bank_Sort_Code)) echo "Valid Bank Sort Code"; else echo "Invalid Bank Sort Code"; } ?> This i thought would validate the text box but nothing happens. any ideas what I am doing wrong and how to correct it? Cheers! Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted August 19, 2009 Share Posted August 19, 2009 You are trying to call php function from javascript, which is not possible. It is not possible because php is rendered on server before the client sees the page in browser, then when the page is loaded to clients browser we can play around with javascript (which is client side code). You should do the validation on submit in server side and in addition you can do it in the client side on the fly with javascript. But you just cant mix javascript and php like that. And also the php variable does not exists in your html/js code what you are tryign to use also in the onblur event ($Bank_Sort_code). Quote Link to comment 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.