Question:

I am new to JQuery. I wanna passing my values to another page using Jquery by clicking on 2nd button instead on submit button. I tried echo what values it carried to another page (a.php) and I got, "[object HTMLInputElement]". There's no values on a.php page. I got "array(0) { } " when i print_r[$_POST] on it. Cant somebody tell me what wrong with my code? Sorry for my english.

Here is my JQUery code:

**JQuery :**

    function validate(form)
    {       

        with(form)
        {

                if (d1.value == "")
                {
                alert('Empty on d1');
                d1.focus();
                return false;
                }


                if (d2.value == "")
                {
                alert('Empty on d2');
                d2.focus();
                return false;
                }   

                if ((vot[0].checked =="") && (vot[1].checked =="") && (vot[2].checked =="")) 
                { 
                alert ('Choose your vot'); 
                return false; 
                } 

                if (program_list.value == '0'||program_list.value=='')
                {
                alert('Choose ur program');
                program_list.focus();
                return false;
                }

                var postData = {

                    d1: $("#input:d1").val(),
                    vot: $("#vot").val(),
                    d2: $("#input:d2").val(),
                    program_list: $("#program_list").val(),

                };

                $.ajax({
                    type: "POST",
                    url: "a.php",
                    data: postData, 
                    success: function(data){
                    window.open("a.php"); 
                }

                }); 

        };

    return true;
    };

**HTML :**

<form name="form" action="a.php" method="post" onSubmit="return validate(this)" >
<table width="1100" border="0" align="center" bgcolor="#FFFFFF">

  <tr>
    <td>
        <table width="550" border="0" align="center" bgcolor="#FFFFFF">

         <tr>
            <td width=131><span class="style1">text1<font color="#FF0000">*</font></span></td>
            <td width=13><span class="style1">:</span></td>
            <td width=392><input name="d1" id="d1" type="text" size='12' maxlength="12"></td>
        </tr>  

        <tr>
            <td width=131><span class="style1">vot <font color="#FF0000">*</font></span></td>
            <td width=13><span class="style1">:</span></td>
            <td width="392">
                <table width="350" border="0" align="LEFT">

                  <tr>
                    <td width=150 class="style9"><input type="radio" name="vot" id="aa" value="1"</td>
                    <td width=120 class="style9"><input type="radio" name="vot" id="bb" value="2"</td>
                    <td width=80 class="style9"><input type="radio" name="vot" id="cc" value="3"</td>
                  </tr>

                </table>
            </td>
        </tr>

         </table>
    </td>

    <td>
    <table width="550" border="0" align="center" bgcolor="#FFFFFF">

    <tr>
        <td width=150><span class="style1">text2<font color="#FF0000">*</font></span></td>
        <td width=15><span class="style1">: </span></td>
        <td width=371><input  type="text" name="d2" id="d2" size='12' maxlength="12"> </td>
    </tr>    

    <tr>
        <td width=150><span class="style1">program <font color="#FF0000">*</font></span><br><span class="style5"><i>Press & Hold the Ctrl button</i> to choose more than one</span></td>
        <td width=15><span class="style1">:</span></td>
        <td width=350 class="style1"><div id="program_list"><select name="program_list" id="program_list"><option value="0">-- xx --</option></select></div></td>      
    </tr>

    </table>
    </td>

</tr>
</table>

<table width="1110" border="0" align="center" bgcolor="#FFFFFF">
  <tr>
        <td>
            <table width="600" border="0" align="center">
                <tr>
                    <td width="300" align="right">
                    <input type="submit" name="view1" value="VIEW1"> 
                    </td>
                    <td width="300" align="left">
                    <input type="button" name="view2" id="view2" value="VIEW2" onClick="validate(this.form);">
                    </td> 

                </tr>
            </table>
        </td>
  </tr>
</table>

</form>
$.ajax({
    type: "POST",
    url: "a.php",
    data: postData,
    success: function(data){
        window.open("a.php");
    }
}); 

Instead of doing something with the response you open a.php again but without sending any data.

If you just want a different button to do the submitting you can use submit().

thanks for your help. at first i dont get what u said here, thanks a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.