Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-28-2007, 12:48 PM   PM User | #1
traxion
New Coder

 
Join Date: Mar 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
traxion is an unknown quantity at this point
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
traxion is offline   Reply With Quote
Old 03-28-2007, 05:25 PM   PM User | #2
A1ien51
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
A1ien51 will become famous soon enough
You just add another query string parameter.

url=url+"&foo="+ bar

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 03-29-2007, 07:47 AM   PM User | #3
traxion
New Coder

 
Join Date: Mar 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
traxion is an unknown quantity at this point
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
traxion is offline   Reply With Quote
Old 03-29-2007, 04:58 PM   PM User | #4
david_kw
Senior Coder

 
Join Date: Nov 2006
Posts: 1,000
Thanks: 0
Thanked 0 Times in 0 Posts
david_kw will become famous soon enough
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
david_kw is offline   Reply With Quote
Old 03-30-2007, 05:22 AM   PM User | #5
iLLin
Regular Coder

 
Join Date: Oct 2005
Location: Right Here
Posts: 654
Thanks: 1
Thanked 0 Times in 0 Posts
iLLin is an unknown quantity at this point
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.
iLLin is offline   Reply With Quote
Old 03-30-2007, 07:55 AM   PM User | #6
traxion
New Coder

 
Join Date: Mar 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
traxion is an unknown quantity at this point
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
traxion is offline   Reply With Quote
Old 03-30-2007, 08:38 AM   PM User | #7
traxion
New Coder

 
Join Date: Mar 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
traxion is an unknown quantity at this point
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
traxion is offline   Reply With Quote
Old 03-30-2007, 04:48 PM   PM User | #8
david_kw
Senior Coder

 
Join Date: Nov 2006
Posts: 1,000
Thanks: 0
Thanked 0 Times in 0 Posts
david_kw will become famous soon enough
Exactly what are "both variables"? I see 3 named elements in the form. What does your showUser function look like now?

david_kw
david_kw is offline   Reply With Quote
Old 04-02-2007, 04:26 PM   PM User | #9
iLLin
Regular Coder

 
Join Date: Oct 2005
Location: Right Here
Posts: 654
Thanks: 1
Thanked 0 Times in 0 Posts
iLLin is an unknown quantity at this point
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.
iLLin is offline   Reply With Quote
Old 04-03-2007, 08:40 AM   PM User | #10
traxion
New Coder

 
Join Date: Mar 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
traxion is an unknown quantity at this point
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
traxion is offline   Reply With Quote
Old 04-03-2007, 09:44 AM   PM User | #11
david_kw
Senior Coder

 
Join Date: Nov 2006
Posts: 1,000
Thanks: 0
Thanked 0 Times in 0 Posts
david_kw will become famous soon enough
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
david_kw is offline   Reply With Quote
Old 04-04-2007, 09:12 AM   PM User | #12
traxion
New Coder

 
Join Date: Mar 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
traxion is an unknown quantity at this point
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
traxion is offline   Reply With Quote
Old 04-04-2007, 03:48 PM   PM User | #13
david_kw
Senior Coder

 
Join Date: Nov 2006
Posts: 1,000
Thanks: 0
Thanked 0 Times in 0 Posts
david_kw will become famous soon enough
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
david_kw is offline   Reply With Quote
Old 04-04-2007, 03:51 PM   PM User | #14
david_kw
Senior Coder

 
Join Date: Nov 2006
Posts: 1,000
Thanks: 0
Thanked 0 Times in 0 Posts
david_kw will become famous soon enough
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
david_kw is offline   Reply With Quote
Old 04-05-2007, 08:54 AM   PM User | #15
traxion
New Coder

 
Join Date: Mar 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
traxion is an unknown quantity at this point
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
traxion is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:52 AM.


Advertisement
Log in to turn off these ads.