Jump to content

Calling function with an onblur event in a textbox


El_Dudereno

Recommended Posts

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!

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.