Jump to content

Splitting an AJAX return string in to separate element ID's for separate fields


josephpruski

Recommended Posts

I've banged my head against the wall on this for the past few days finally reaching this point...

 

I've created a drop down menu that can now sucsessfully return a string of values from a MySQL database. I'm wanting to dynamically update multiple text boxes with each part of data when entering a form. (Simple terms... User selects a "Venue" from the dropdown, and the text boxes below automatically display the "Venue"'s information in each box (Address, Address2, City, State, etc...)

 

So right now, when the drop down menu is selected, I can't get the string to separate and give each (substring?) an ID to show in separate text boxes.

 

I know I'm halfway there because I can go back to the basics and leave the return string alone and sucsessfully show up in a single text box with the separator between each piece of data from the database.

 

(i.e.: Venue_ID/Venue_Name/Venue_City/etc.)

 

Any thoughts? Jokes? Code Help? Here's the basic code I'm using...

 

Java:

 

function getVenueInfo(strURL)

{

var req = getXMLHTTP();

if (req)

{

//function to be called when state is changed

req.onreadystatechange = function()

{

//when state is completed i.e 4

if (req.readyState == 4)

{

// only if http status is "OK"

if (req.status == 200)

{

document.getElementById('venue_id').value=req.responseText;

 

}

else

{

alert("There was a problem while using XMLHTTP:\n" + req.statusText);

}

}

}

req.open("GET", strURL, true);

req.send(null);

}

}

 

PHP:

 

$sql="SELECT * FROM Q_Venues WHERE Venue_ID = '".$venue."'";

 

$result = mysql_query($sql);

 

 

while($row = mysql_fetch_array($result))

  {

  echo $row['Venue_ID'];

  echo "/";

  echo $row['Venue_Name'];

  echo "/";

  echo $row['Venue_City'];

  }

 

?>

 

Body Code:

 

<p>Venue :

  <select name="venue" onChange="getVenueInfo('find_ccode.php?venue='+this.value)">

  <option value="">Select Venue</option>

  <?php

do { 

?>

  <option value="<?php echo $row_Venues['Venue_ID']?>"><?php echo $row_Venues['Venue_Name']?></option>

  <?php

} while ($row_Venues = mysql_fetch_assoc($Venues));

  $rows = mysql_num_rows($Venues);

  if($rows > 0) {

      mysql_data_seek($Venues, 0);

  $row_Venues = mysql_fetch_assoc($Venues);

  }

?>

</select><br/>

<br/>

ID : 

<input type="text" name="venue_id" id="venue_id" >

<br/>

Name : 

<input type="text" name="ven_2" id="ven_2" > //Where I'm wanting the "Venue Name"

<br/>

City : 

<input type="text" name="ven_3" id="ven_3" > //Where I'm wanting the "Venue City"

  </form>

 

And so forth...

 

 

 

Thanks for any help. After lots of researching I'm learning that most of you guru's are probably sick of seeing these, but I'm a newbie on a mission...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.