Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    New Coder
    Join Date
    Mar 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php js ajax: 2 variable with ajax

    hey all

    i got a small problem.. i made a page with php, js and ajax. that works great but now i want to add a 2de variable to the page so that i can do more think

    i've got now a pulldownlist where i can select a week. and i want to add 3 radio button to it so i can chose a week and then change between the radiobuttons

    is the code i use for the js (with 1 var)

    Code:
    function showUser(str)
    {
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
     {
     alert ("Browser does not support HTTP Request")
     return
     }
    var url="includes/realisatie.incl.php"
    url=url+"?q="+str
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    }
    and the code of the radiobuttons
    PHP Code:
    <form action="index.php?pagina=includes/opties.realisatiemaken" method="get">
                        <input type="hidden" name="pagina" value="includes/opties.realisatiemaken">
                        <INPUT TYPE="button" onClick="showUser(this.name)" name="<?php     echo $weekid?>" value="Update">
                        <input type="submit" value="Realisatie vernieuwen">
                       
                        <input type="radio" name="type" value="1" >     Realisatie
                        <input type="radio" name="type" value="2" >         Verschil
                        <input type="radio" name="type" value="3" CHECKED>         Alles (werkt nog niet)
    i tryed to fix it by mine own but i cant get 2 variable into the ajax

    does anybody of u got an solution??

    when u want more info just ask.. i hope u get the problem

    Traxion

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You just add another query string parameter.

    url=url+"&foo="+ bar

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New Coder
    Join Date
    Mar 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by A1ien51 View Post
    You just add another query string parameter.

    url=url+"&foo="+ bar

    Eric
    jea.. but how do i get that in html?

    because i would like to do it with out any more buttons on the form

    when i change a radiobutton now the var from the pulldownlist is gone and then the query isnt good anymore so my page is useless

  • #4
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm not sure I understand the question but if you add an id to the form

    <form id="aform" action="index.php?pagina=includes/opties.realisatiemaken" method="get">

    You can get the value of the radio button by

    Code:
    .
    .
    .
    url=url+"?q="+str
    for (var i = 0; i < document.aform.type.length; i++) {
      if (document.aform.type[i].checked) {
        url=url+"&type=" + document.aform.type[i].value;
      }
    }
    url=url+"&sid="+Math.random()
    .
    .
    .
    Or something similar. I really haven't done that much work with radio buttons.

    david_kw

  • #5
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Your using AJAX and forms, why not "post" the form to the AJAX page instead of "get"? Not sure on the max of "get" but when I use forms and AJAX, I always post.

  • #6
    New Coder
    Join Date
    Mar 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by iLLin View Post
    Your using AJAX and forms, why not "post" the form to the AJAX page instead of "get"? Not sure on the max of "get" but when I use forms and AJAX, I always post.
    what is the differnce.. if securaty doesn't matter.. GET is easyer for debugging

    thnx i will try the code

  • #7
    New Coder
    Join Date
    Mar 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    to bad it doesnt work

    i edit the code again and now there is one button lese (that one didnt use the ajax script)

    Code:
    <form id="aform" action="index.php" method="get">
    <input type="hidden" name="pagina" value="realisatie">
    <input type="hidden" name="weekid" value="<?PHP echo $weekid; ?>">
    <input type="radio" name="type" value="1" > 	Realisatie
    <input type="radio" name="type" value="2" > 	Verschil
    <input type="radio" name="type" value="3" > 	Alles (werkt nog niet)
    <INPUT TYPE="submit" onClick="showUser(this.name)" name="<?php 	echo $weekid; ?>" value="Update">
    </form>
    i tryed stuff like in the radiobutton on onclick but then i only get the valua of the radiobutton

    i still dont get how i get both variables into ajax

  • #8
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Exactly what are "both variables"? I see 3 named elements in the form. What does your showUser function look like now?

    david_kw

  • #9
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by traxion View Post
    what is the differnce.. if securaty doesn't matter.. GET is easyer for debugging

    thnx i will try the code
    The difference? Besides if you have a long form and your GET url gets chopped... and post is more secure? Easier to debug? How? print_r($_REQUEST) does both.

  • #10
    New Coder
    Join Date
    Mar 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by david_kw View Post
    Exactly what are "both variables"? I see 3 named elements in the form. What does your showUser function look like now?

    david_kw
    variable 1 weekid
    variable 2 type

    the var pagina i dont need for the ajax

    Code:
    function showUser(str)
    { 
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
     {
     alert ("Browser does not support HTTP Request")
     return
     } 
    var url="includes/realisatie.incl.php"
    url=url+"?q="+str
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChanged 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    }
    it works right now with only weekid

    now i want that i can pick a weekid.. and the page change to that week

    and then i need to change the type so that the page change on somethings but the weekid must stay the same.

    if type is emty it should be standaard on 3 (i can build that bym ine own)

    i hope that u get the problem

    already thnx
    Traxion

  • #11
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by traxion View Post
    variable 1 weekid
    variable 2 type
    So did you try the code in my earlier post? Here it is again.

    Code:
    function showUser(str)
    { 
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
     {
     alert ("Browser does not support HTTP Request")
     return
     } 
    var url="includes/realisatie.incl.php"
    url=url+"?q="+str
    for (var i = 0; i < document.aform.type.length; i++) {
      if (document.aform.type[i].checked) {
        url=url+"&type=" + document.aform.type[i].value;
      }
    }
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChanged 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    }
    david_kw

  • #12
    New Coder
    Join Date
    Mar 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i tryed that but he doesnt seem to find the aform

    document.aform has no properties
    showUser("13")realisatie.ajax.j... (line 14)
    onchange(change )index.php (line 1)
    [Break on this error] for (var i = 0; i < document.aform.type.length; i++) {...


    i tryed to get that out by a if statment..

    if (document.aform.type.length !== ""){
    for (var i = 0; i < document.aform.type; i++) {
    if (document.aform.type[i].checked) {
    url=url+"&type=" + document.aform.type[i].value;
    }
    }
    }

    i dont now i do that so correctly?
    but he seems to ask for that "document.aform has no properties"

    Code:
    <form id="aform" method="get">  
    <br>
    <input name="type" value="3" type="hidden">
    <select name="weekid" onchange="showUser(this.value)">
    
    <option value="">Maak uw keuze</option>	
    <option value="18">weeknr 13 2007 (2007-03-27)</option>	
    <option value="17">weeknr 12 2007 (2007-03-19)</option>	
    </select>
    </form>
    to make it all more implicated (and im sorry for posting this now, i should be doing this much ealier). this is the code from the 1ste form when i open and call the first time the ajax

    the code i post in a post above is the form what i call when i calt this one already..

    im srry that i didnt tell that earlyer

  • #13
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm, try adding a name field as well. That should fix being able to find the form at least.

    <form id="aform" name="aform" method="get">

    david_kw

  • #14
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Umm, on this one the input named 'type' is not a radio button but rather a hidden field. If that is the case you don't have to do the loop at all but instead just

    url=url+"&type=" + document.aform.type.value;

    pretty much just like A1ien51 said in the first response.

    david_kw

  • #15
    New Coder
    Join Date
    Mar 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oke i will try that

    my company just update the sql server from 3.xx to 5..

    some querys dont work anymore.. and the page load is way to long.

    i must try to fix that first.. then i will try the ajax again.. thnx for all the support from here


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •