0

Hello I'm have this idea for a part of the database I'm building but my javascript knowledge is lacking entirely (I'm a software engineering student and we touched on javascript once and I barely remember anything we did).

I have a form where a user is entering the details for a book, title, author, summary etc. What I would like it do it is check and see if the author is all ready in the database, if so nothing happens if not a text box appears in the form for them to enter in the authors biography. I'm fairly certain I need javascript to do this, but I'm entirely new to it and don't know where to start exactly.

Thanks.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by twiss
0

In other words, you want to check the user input, before a form is submitted?
First, assign a submit handler:

document.getElementById('form_id').onsubmit = function() {
  // some validating code
};

If I understand you right, you want to access the database, to check if the author exists? Be careful with this. If J. K. Rowling is in the database, and someone enters Joanne Rowling, what happens?

Anyway, you'll need to write a script in PHP or another server-side language, that looks for the name in the database and prints some sort of result. If you want to check this before submit, you'll have to use AJAX.

It's a bit strange, however, if you
- click the submit button
- get the input
- request a php page
- process the result, decide if the submit is cancelled or not
- if it is not, submit the form (request another page)

It's much more efficient if you just submit the form, check some stuff in PHP, and insert some things in the database (or not).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.