I am new to Ajax/XMLHttpRequest
and am trying to understand it.
I am working on an inventory program that basically adds tools to a box. On the main page (MainPage.php
, for instance), there a textbox in a form that a user can start to type in the name of the tool in order to add it to the box. I'm playing with XMLHttpRequest
right now to search for the tool in a MySQL
database with the MySQL
LIKE
syntax. On the handler page (HandlerPage.php
) there is code to search for the tool using SQL
Like. The search results are displayed in a HTML DIV on the main page. It works great...
The search results are wrapped in a form and displayed as a link. The location of this wrapper function is in HandlerPage.php
:
function createLink($pri_key,$button_name,$file_to_call, $other){
$html_str = "<form id='tool_form' action='".$file_to_call."' method='post'>";
$html_str .= "<input style='display:none;' name='prikey' type='text' value='".$pri_key."' >";
$html_str .= "<input style='display:none;' name='compt_prikey' type='text' value='".$other."' >";
$html_str .= "<input id='view_button' type='submit' value='".$button_name."' class='no_button'>";
$html_str .= "</form>";
return $html_str;
}
There is a JQuery
event handler waiting for the user to click
on the link. However, this event handler is never called. The form is submitted, but the event handler is not called. (Also, there is another form and event handler, both coded into MainPage.php
that function as expected.)
$("#tool_form").submit(function(){
//some code
return true;
});
Where is the form submitted, or better yet, on what page is the event triggered? In HandlerPage.php
or MainPage.php
? I'm assuming it is being triggered on HandlerPage.php
, but I don't understand why....
Also, as a side question, is there going to be a problem with multiple search results having the same id? Should I use an event handler with a class instead?