Jump to content

Calling Ajax Twice in a Page Causing Problem


phpmady

Recommended Posts

Hi,

 

I  am calling the ajax twice in a page,

 

<div class="login_form">


<div class="row">
     
         <span class="label">رقم الجوال<span class="men">*</span></span>
         <span class="formw">
        <input type="text" class="textbox_forms required" name="SMS_Mobile" id="SMS_Mobile" size="50" onblur="[b]chkUser[/b](this.value);" dir="ltr"></span>
    </div>



   <div class="row" id="[b]user_already[/b]">
    </div>



<div class="row" id="choose_any_type">
       <span class="label">Send By</span>
         <span class="formw">
         
         		<span>
              م :
              <input type="radio" value="format_message" name="message_type" onclick="call_format_message();">  
              </span>
              
             
         		<span>
              ش :
              <input type="radio" value="custom_message" name="message_type" onclick="call_custom_message();">  
              </span>
              
              
              </span>
    </div>
    
    

    
    <div id="div_format_message" style="display:none;">
    <div class="row1"><span class="label">Format Message</span>
    <span class="formw" dir="">
    <select name="F_ID" id="gt" onchange="[b]ajax_call_format_message[/b](this.value);">
    <option value="">Select SMS Template</option>
     <!-- START BLOCK : format_msg_send_one -->
    <option value="{F_ID}" {for_selected}>{F_Title}</option>
    <!-- END BLOCK : format_msg_send_one -->
    </select>
</span>
    </div>
    
    
    <div class="row" id="show_div_format_message">
      </div> 
  
    </div>
</div>

 

 

when i am calling the chkUser actually am asking to bring the ajax content in the div called

 

 

  <div class="row" id="user_already">

    </div>

 

but the content is placing the div called

 

<div class="row" id="show_div_format_message">

      </div>

 

Why its placing the content in a different location.

 

 

Here is my js for chkUser

 

// JavaScript Document

var xmlhttp;
//function namechange(name_fieldvalue)

function chkUser(mobile_number)
{

xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }
var url="ajax_user_operate.php";
url=url+"?mobile_number="+mobile_number;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {

  document.getElementById("user_already").innerHTML=xmlhttp.responseText;
  }
}


function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

 

 

and js for ajax_call_format_message();

 

 


// JavaScript Document

var xmlhttp;
//function namechange(name_fieldvalue)

function ajax_call_format_message(F_ID)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }
var url="ajax_show_format_message.php";
url=url+"?F_ID="+F_ID;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {

  document.getElementById("show_div_format_message").innerHTML=xmlhttp.responseText;
  }
}


function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

 

I seriously doubt the Js file, am i doing wrong..

 

Thanks,

This line places the ajax response into the div:

document.getElementById("show_div_format_message").innerHTML=xmlhttp.responseText;

 

And yes this places it in <div id="show_div_format_message">

 

Change that line to

 

document.getElementById("user_already").innerHTML=xmlhttp.responseText; to put it where you wanted.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.