tags:

views:

19

answers:

1

hello all,

The situation is that the user enters a value in the textbox.Now whenever user enters the value, the value is to be compared to a value(field) which has been retrieved form the database.If the value the user has entered is higher than that of the database then they should be displayed with a popup.How do i do that?The language which i am using is PHP.The popup should be automatic

Thanks in advance

+1  A: 

Online demo of following example: http://jsbin.com/ezusi3/

You can't do "popups" with PHP. You'll need to use a client-side solution, like Javascript. Below is a simple function that you could call in order to do what you are asking:

function checkVals() {
  // Retrieve the user-provided value
  var userVal = Number(document.getElementById("userVal").value);
  // Retrieve the server-provided value
  var dataVal = Number(document.getElementById("dataVal").value);
  // If the user value is too high, alert the user
  if (userVal > dataVal) {
    alert("Your value is too high.");
  }
}

Note that this is a Javascript function, not a PHP function.

Jonathan Sampson
the thing is that i am storing the data entered by the user in a php variable.how do i access that in the javascript function
swathi
`<input type='text' id='dataVal' value='<?php print $var; ?>' />`
Jonathan Sampson
So if my textbox is like <input type="text" name="random1" value="<?=$random1?>" onblur=checkvalue()>then in the javascript i would be doing something like <script type="text/javascript">function checkvalue(){ var ran1 = document.getElementsByName("random1").value;}</script>
swathi
@swathi: Yes. You'll note that this is essentially what I did in my example. If this answer was helpful, please consider accepting it by checking the check-mark beside it.
Jonathan Sampson