|
Posted by Sandman on 11/27/06 05:41
Hello,
I'm building a website in PHP and Javascript. The registration
portion is divided into 2 sections:
1. In one, I get info about the visitor. This is sent via POST to a php
script which is section 2.
2. In the second section, I get some specific information about their
pets and make suggestions. I'm having problems with section 2, and I
hope y'all can help.
The core of the PHP script in Section 2 consists of the following:
<?php
for ($n=1; $n <= $num; $n++) {
print "Please enter age of pet #$n:" ;
print "<INPUT type='text' name='petage'>      " ;
$div = $n . "ajaxDiv" . ";";
$_ENV['div'] = $div;
print "DIV IS: $div<br><br>";
print "<INPUT TYPE='button' onClick='ajaxFunction()' NAME='$age'
VALUE='Done!'>" ;
print "<INPUT TYPE='reset' NAME='Clear' VALUE='Reset form'>
<br><br>" ;
print "<div id='$div'></div><br><br>" ;
}
ajaxfunction() looks like:
if(ajaxRequest.readyState == 4){
var div = "<?php echo $_ENV['div']; ?>";
if (div = "") {
div = "1ajaxDiv";
}
var ajaxDisplay = document.getElementById('div');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
// Get pet stores based on zipcode
var zipcode = "<?php echo $zip; ?>"
var querystring = "?zipcode=" + zipcode;
ajaxRequest.open("GET", "getstores.php" + querystring, true);
ajaxRequest.send(null);
The idea is that the user fills in the age of their pet, I look in my
DB and spew out the names and addresses of vets and pet stores in the
area. Thanks to ajaxfunction(), I can do this through:
print "<INPUT TYPE='button' onClick='ajaxFunction()' NAME='$age'
VALUE='Done!'>" ;
The function calls another PHP script and outputs the data in the same
HTML file.
So here is my issue. This code works fine when there is only one pet.
If there are more than one, then clicking on the second button results
in no output at all.
Any suggestions?
I was thinking of enclosing it in a form like so:
<form method="post" action="/cgi-bin/samescript.php">
loop to output buttons
</form>
Meaning call the same script after clicking the first button, second
button and so on.
But I would then need to change:
print "<INPUT TYPE='button' onClick='ajaxFunction()' NAME='$age'
VALUE='Done!'>" ;
so when the user clicked on it, it would call ajaxFunction() AND the
PHP script.
Is this possible?
Thanks for listening and have a GREAT holiday season!!
Navigation:
[Reply to this message]
|