Hi there, I'm trying to modify a form verification script. When you press the submit button it runs a javascript function that checks if the required fields are filled out. If not it sends up an alert and doesn't submit the form. What I'd like to do is have it also check that a certain field isn't all ready in the database. Is there a way for me to pass a javascript var to an sql query? I know client side vs. server side so there probably isn't an easy way to accomplish this?

Recommended Answers

All 2 Replies

Hi there,

Look @ AJAX, i.e. create a php function that will return a boolean of true or false if a given variable is passed to it
then using AJAX calls in javascript, pass the variable to the function and proceed accordingly

The mentioned function is what will check for the value in the database

To fit with your program flow, you probably need to use Ajax as mentioned in the previous post. In a simple situation, you can use some Javascript to pass variables to PHP by calling a PHP program with parameters. An example of passing the screen dimensions to PHP:

if ($_SESSION['scrn_info_sw'] <> "set") {
        echo "<script language='JavaScript'>
            var w = screen.width;
            var h = screen.height;
            $_SESSION['scrn_info_sw'] = "set";

If you are trying to avoid screen refreshes and do everything interactively, then this obviously isn't the right solution but I thought that I'd show you this approach so you understand the options.

[I'm having a problem with Markdown so I left this as plain text. Need to do some experimenting!]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.