homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Javascript - Function Parameter As Variable

10+ Year Member

Msg#: 4380481 posted 2:23 am on Oct 28, 2011 (gmt 0)


I am having a problem with an onclick event, inside a div, that is in another div which the content of said div is an AJAX'd search result. The onclick event basically renews the search using a different parameter, that is found during the first search - basically the function checks to see whether or not a city name is spelled correctly or not. If not, then a button is presented to click to change the search results.

AJAX / Javascript Code:

<script language="javascript">
function ajaxgetter(variable) {
var stuff = variable;
var mygetrequest = new ajaxRequest();
mygetrequest.onreadystatechange = function() {
if (mygetrequest.readyState == 4) {
if (mygetrequest.status == 200 || window.location.href.indexOf("http") == -1) {
document.getElementById("result").innerHTML = mygetrequest.responseText;
alert("An error has occured making the request");

var namevalue4 = encodeURIComponent(document.getElementById("name9"+stuff).value);
var agevalue4 = encodeURIComponent(document.getElementById("age9"+stuff).value);
var utvalue4 = encodeURIComponent(document.getElementById("ut9"+stuff).value);
document.getElementById("result").innerHTML = "<center><b>Loading...</b></center><br><center><img src='images/ajax-loader1.gif' /></center>";
mygetrequest.open("GET", "newdealerfinder.php?location="+namevalue4+"&distance="+agevalue4+"&ut="+utvalue4"&r="+ Math.random(), true);

The code above is using a variable brought up by the 2nd search. Here is the relevant PHP code to do the 2nd search:

if($miles1 > 2) {
echo "<form action='' method='get' />
<input type='hidden' value='$city->lat,$city->lng' id='name9$javacounter' name='name9$javacounter' />
<input type='hidden' value='$currentunixtime' id='ut9$javacounter' name='ut9$javacounter' />
<input type='hidden' value='$distance' id='age9$javacounter' name='age9$javacounter' />
<input type='button' value='Change Location' onClick='ajaxgetter($javacounter)' />

By using Firebug, I can see that the proper ids are being set, and if anyone wants to take a look at the script in question, I can post a link.




10+ Year Member

Msg#: 4380481 posted 8:30 am on Oct 28, 2011 (gmt 0)

Disregard, its working now. All I did was write the same code out again.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved