onclick passing more than 1 arguments in Ajax Java function

Discussion in 'JavaScript' started by jasso, Aug 22, 2009.

  1. #1
    I have a radio button as an input and while onclick the Ajax java script function "processvalue" will be called by passing value of the radio button ('1' or '0') as well as a php variable...(say '<?php echo $event['eventid']; ?>').

    How can I go about passing more than 1 arguments in the function and also then pass the values to the PHP file that will be called via the ajax function?

    Example:

    PHP/HTML:

    <?php echo "YES"; ?>: <input type="radio" name="vote" value="1" onclick="getVote(this.value,'<?php echo $event['eventid']; ?>')" /> <?php echo $lang['NO']; ?>: <input type="radio" name="vote" value="0" onclick="getVote(this.value),'<?php echo $event['eventid']; ?>'"/>



    Ajax:


    function processvalue(vote,id)
    {
    if (str.length==0)
    {
    document.getElementById("Answer").innerHTML="";
    return;
    }

    var xmlHttp;
    try {
    xmlHttp=new XMLHttpRequest();
    }
    catch (e) {
    try {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
    try {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) {
    alert("Your browser does not support AJAX!");
    return false;
    }
    }
    }
    xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState==4) {
    document.getElementById("Answer").innerHTML=xmlHttp.responseText;
    }
    }
    var url="show.php";
    url=url+"?q="+vote;
    url=url+"&t="+id;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    }


    PHP:(show.php)

    <?php
    $xvote = $_REQUEST['vote'];
    $xevent=$_GET["id"];

    echo $xvote;
    echo $xevent;
    ?>
     
    jasso, Aug 22, 2009 IP
  2. jasso

    jasso Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Is there no one could give a direction ?...:confused:
     
    jasso, Aug 23, 2009 IP
  3. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #3
    in your code, you call show.php and pass 2 variables to it:
    the variable names are q and t so your show.php page should look like this:

    $xvote = $_REQUEST['q'];
    $xevent=$_GET["t"];

    echo $xvote;
    echo $xevent;

    ok?
     
    NoamBarz, Aug 23, 2009 IP