1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

AJAX giving problems

Discussion in 'PHP' started by arvind_srivastava, Nov 18, 2008.

  1. #1
    I am having an AJAX issue with my code and any help will be appreciated. I have a page at http://getvalueleads.com/provider_registration.php. If you see in the last paragraph of the page where it says Lead Information, there is a drop down for Select Industry, when you select Web Design from there the options are shown below. This is done via AJAX. However when a user selects (checks a box) for any of the subcategory I am not able to save this information in the database through AJAX. I just am not able to find where the information is there in the code to take it from and how to save the value in database.

    [FONT=&quot]Any help will be appreciated.


    Thanks
    Al
    [/FONT]
     
    arvind_srivastava, Nov 18, 2008 IP
  2. Sneef

    Sneef Peon

    Messages:
    212
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you need help you will need to post the AJAX code for some people to read and tell you where to make changes.
     
    Sneef, Nov 18, 2008 IP
  3. BenjArriola

    BenjArriola Peon

    Messages:
    175
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Are you the programmer of this form?

    If all form tags have a name and value, they are passed in the form. I notice you are using PHP and you can do is check the whole $_POST array with foreach. The values should be in there somewhere.

    Check: http://us.php.net/foreach

    Now if ever it is not there, then, there is a problem with your form itself. I understand it is AJAX, but as long as they update the form input tags aside from changing the displayed content on the screen, it should still be passing values properly.
     
    BenjArriola, Nov 18, 2008 IP
  4. juust

    juust Peon

    Messages:
    214
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    close the alert() with ;

    function submitform(){
    alert('jay');
    document.frmregistration.action="provider_registration.php?pop=yes";
    document.frmregistration.method="POST";
    document.frmregistration.submit();
    return true;
    }

    otherwise the submitform() code does not run.
     
    juust, Nov 18, 2008 IP
  5. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #5
    It doesn't matter in javascript , I mean the semicolon ( ; )
     
    ads2help, Nov 19, 2008 IP
  6. juust

    juust Peon

    Messages:
    214
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Does it ?
    I got my head stuck in php-mode, I think.
     
    juust, Nov 19, 2008 IP
  7. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Its doesnt matter good practice to have though .. but the part is that i think you may not understand is AJAX is only the middle man for the PHP.. Ajax doesn't do any functions to the database just tells the browser to do things in a manner it doesnt have to refresh.

    It would be a great idea to post code can't get any help without it only ideas
     
    atlantaazfinest, Nov 19, 2008 IP
  8. arvind_srivastava

    arvind_srivastava Well-Known Member

    Messages:
    1,229
    Likes Received:
    153
    Best Answers:
    0
    Trophy Points:
    130
    #8
    *********************FUNCTION To Call AJAX Start Here***************************

    <SCRIPT language=javascript>
    var xmlHttp



    function catChanged(){
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
    document.getElementById("subcat").innerHTML=xmlHttp.responseText;
    }
    }





    function oncat_change(cat_id){
    if(cat_id==""){
    }else{
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
    alert ("Browser does not support HTTP Request")
    return
    }

    var url="subcat_table.php?cat_id="+cat_id+"&sid="+Math.random()
    xmlHttp.onreadystatechange=catChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    }
    }

    </SCRIPT>

    *********************FUNCTION To Call AJAX END Here***************************

    *********************HTML AND PHP CODE Where I am Populating the Sub category on select of Industries******************


    <TABLE cellSpacing="5" cellPadding="2" width="75%" border="0" bgcolor="#FBDFB7" style="border:1px solid #F4A835;">
    <FORM name="frmregistration" method="post" onSubmit="javaScript: return validate_registration();">

    <tr>
    <td class="text" width="35%" align="right" valign="top">Industry:</td>
    <td valign="top" width="60%">
    <Select name="cat_id" class="input" style="width:250px" id="cat_id" onchange="oncat_change(this.value, '')">
    <option value="">Select a Industry</option>
    <?//adding options to select tag i.e Models
    $strsql="select * from gml_category where 1=1";
    $result=mysql_query($strsql);
    echo mysql_error();
    while($objrs=mysql_fetch_array($result)){
    $slcat_id=$objrs['cat_id'];
    $cat_name=$objrs['cat_name'];

    ?>
    <option value="<?echo $slcat_id;?>" <? if($slcat_id==$cat_id){echo "Selected";}?>><?echo $cat_name;?></option>
    <?
    }
    ?>
    </select>

    </td>
    </tr>



    <!--Populating Dynamic Sub Category From the data base using AJAX -->

    <tr>
    <td class="text" colspan="2" align="center">
    <div id="subcat">
    </div>
    </td>
    </tr>


    <TR>
    <TD class="largetext" valign="top" align="center" colspan="4">
    <input type="image" src="images/register_now.gif"/>&nbsp;
    </TD>
    </TR>


    </table>
    </FORM>

    *****************************************END ********************************************


    *********************************Code In (subcat_table.php) START HERE******************************

    <?php
    include("lib/inc.php");

    $cat_id=$_REQUEST['cat_id'];
    //$cat_id=2;

    if($cat_id!=""){

    $ctr=0;
    $strsql="select * from gml_subcategory where cat_id=".$cat_id;
    $result=mysql_query($strsql);
    echo mysql_error();
    $ctr=0;
    while($objrs = mysql_fetch_array($result)){
    $subcat_id=$objrs['subcat_id'];
    $bid_price=$objrs['bid_price'];
    $subcat_name=$objrs['subcat_name'];
    $leadboxname=$ctr;



    $option.="<tr>";
    $option.="<TD class='text' align='left'><input type='checkbox' id='subcat_id'"; $option.=" name='subcat_id[]' class='text' value=<".$subcat_id.">&nbsp;&nbsp;".$subcat_name;
    $option.="</TD>";

    $option.="<TD class='text' valign='top' align='left'><input type='text' name=txt". $subcat_id."value=".$txt_default."class='input' size='5' maxlength='3'></TD>";
    $option.="<TD class='text' valign='top' align='left' width='25%'>$".$bid_price."</TD>";
    $option.="</tr>";

    $ctr+=1;
    }
    }


    //echo $option;

    //exit;

    ?>

    <table width="70%" valign="top">

    <tr colspan="2"><td class="text">List of available Sub Category</td></tr>
    <tr bgcolor="#f3f3f3">
    <td align="left" class="text" width="50%"><b>Sub Category </b></td>
    <td align="left" class="text" width="25%"><b>Max Lead</b></td>
    <td align="left" class="text" width="25%"><b>$Price&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
    </tr>
    <? echo $option; ?>
    </table>


    Now can someone sort this mess for me :confused::confused:
     
    arvind_srivastava, Nov 19, 2008 IP
  9. garrettheel

    garrettheel Peon

    Messages:
    341
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #9
    This should be in the JavaScript forum, not the PHP one. And what do you mean "sort" through the mess?
     
    garrettheel, Nov 19, 2008 IP