Welcome Guest, Not a member yet? Register   Sign In
using jquery on checking duplicate data in database with dynamic textfields
#1

[eluser]clariz[/eluser]
Could anyone help me on this?

I have dynamic textfields, generated using innerhtml
I want that onblur event, the data in the textfield will be checked for duplicate in the database. The checking will be done without refreshing the page.
Then give an alert if duplicate exists.

I have a code using jquery. I've tried it using static textbox. It works fine.
But when I applied the dynamic textboxes, it doesn't works.

Here's my code:
I have a javascript code and two forms in my html code.
The code goes like this, when I enter a value in my textfield id = Que and on onblur event, the next textfield id = textQuestion gets the value of the textfield id = Que and the form id=formCheck submits the form. The data is process to a php file, checking if the value exists in the database. Then returns a value.


Code:
< script type="text/javascript">
    $(document).ready(function(){
        $('#Que').blur(function(){
            $('#txtQuestion').attr('value', $('#Que').attr('value'));
            $('#formCheck').submit();
        });
                $('#formCheck').ajaxForm({success:show_result});
                });        
                function show_result(responseText){
                        var arr = responseText.split('###');
                        if(arr[0] > 0){
                                alert("Error: Question already exists.");
                        }
                }

< /script>
&lt;form name="formCheck" method="post" id="formCheck" action="&lt;?= site_url("lessons/main/checking");?&gt;"&gt;
        &lt;input type="text" name="txtQuestion" id="txtQuestion" /&gt;
&lt;/form&gt;

&lt;form method="POST" name='formQ' id='formQ' action='&lt;?= site_url("lessons/main/saveAll");?&gt;'&gt;
   <div>
        Question &lt;input type='text' name='Que[]' id='Que' size='38' /&gt;
   </div>
   <div><a href='[removed]addQue()'>add another question</a></div> // this the call to generate dynamic textfields
   <div><span id='newQuestion'></span></div>     // here is where dynamic textfield takes place
&lt;/form&gt;

This is my controller:
It checks the value in the database

Code:
&lt;?php
  class Main extends Controller{
      
      function __construct(){
        parent::Controller();
      }

      function checking(){
        $sql = "Select * from lesson_questions where UCASE(question) = '".strtoupper($_POST['txtQuestion'])."'";
        $qry = mysql_query($sql);
        
            echo mysql_num_rows($qry) . '###';
      }

}
?&gt;


And this is the code to generate dynamic textboxes


Code:
var arrInput = new Array(0);
  var arrInputValue = new Array(0);

function addQue(){
  arrInput.push(arrInput.length);
  arrInputValue.push("");
  displayQue();
}

function displayQue() {
  document.getElementById('newQuestion'). innerHTML="";
  for (intI=0;intI<arrInput.length;intI++) {
    document.getElementById('newQuestion'). innerHTML+=createQue(arrInput[intI], arrInputValue[intI]);
  }
}

function saveQue(intId,strValue) {
  arrInputValue[intId]=strValue;
}

function createQue(id,value) {
  return "Question &lt;input type='text' name='Que[]' id='Que' size='38'&gt;";
}

Please anyone help me on this.
I am new to jquery. Any reply is very appreciated.


-clariz-


Messages In This Thread
using jquery on checking duplicate data in database with dynamic textfields - by El Forum - 09-16-2008, 09:17 PM



Theme © iAndrew 2016 - Forum software by © MyBB