Kenny Pollock
Jul 16 2006, 12:23 AM
Hey guys!
Question: I have a drop down, that when you change it and select another client from it, it fills the fields (name, address, city, state) with the information for the client. It works great, although I don't know how to change the selection in the states drop down.
Example: Kenny is in Hollywood, FL. When you select Kenny from the drop down, it fills the city input field with Hollywood, but isn't changing the states drop down with AL, CA, FL, etc. with the selection of FL, which is Kenny's state.
Any solution?
Chuck_Hicks
Jul 16 2006, 12:26 AM
when you got to print the state dropdown do make sure you put selected in the option of the clients state.
Kenny Pollock
Jul 16 2006, 12:38 AM
Okay but how can I have Javascript do this?
Chuck_Hicks
Jul 16 2006, 01:18 AM
After playing around with the sample on w3cschool.com I think i got a sample that should point you in the right direction.
CODE
<html>
<head>
<script type="text/javascript">
function getOptionIndex()
{
var x=document.getElementById("mySelect")
x.selectedIndex = 1;
}
</script>
</head>
<body>
<form>
Select your favorite fruit:
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<br /><br />
<input type="button" onclick="getOptionIndex()" value="Alert index of selected fruit">
</form>
</body>
Kenny Pollock
Jul 16 2006, 01:25 AM
I think you get what I mean a little, and now I know how to do what I want almost... just tell me this: selectedIndex is the order it appears on the list. So if A was first in the list, and B was second, A would be 1 and B would be 2. How can I have it select 23 for Florida? If I want Florida selected, I have to give it a number to get to Florida...
Chuck_Hicks
Jul 16 2006, 01:32 AM
A would be index 0 and B would b index 1. It works just like an array does.
Kenny Pollock
Jul 16 2006, 01:41 AM
Yeah but without doing if ( Florida) { selectedIndex = 23 } if ( Alabama ) { selectedIndex = 0 } how would I do this?
Chuck_Hicks
Jul 16 2006, 01:53 AM
Actually i am going tochange my post from asking how you are getting the client info to the following.
You know how many states there are it's constent. So all you have to do is do a for loop.
CODE
for(i=0; i<=50; i++)
{
if(x.options[i].txt == state)
{
x.selectedIndex = i;
break;
}
}
sorry if my answers are alittle hard to understand. My head is really twisted around this html logic thing i am trying to do. I know it's posible i am just not as good as matt lol.
Kenny Pollock
Jul 21 2006, 03:16 AM
Sorry for taking so long to reply... I can't seem to get it working.
CODE
if (http.readyState == 4)
{
results = http.responseText;
var brokenstring = results.split("!split!");
document.getElementById('origin_company').value = brokenstring[0];
document.getElementById('origin_contact').value = brokenstring[1];
document.getElementById('origin_address').value = brokenstring[2];
document.getElementById('origin_city').value = brokenstring[3];
document.getElementById('origin_zip').value = brokenstring[5];
document.getElementById('origin_phone').value = brokenstring[6];
document.getElementById('origin_cell_phone').value = brokenstring[7];
for(i=0; i<=50; i++)
{
if(document.new_order.origin_state.options[i].txt == brokenstring[4])
{
document.new_order.origin_state.selectedIndex = i;
break;
}
}
}
Kenny Pollock
Jul 21 2006, 11:06 PM
No one?
Brendon Koz
Jul 21 2006, 11:39 PM
How about an example?
http://www.dhtmlgoodies.com/index.html?pag...ed_select_boxesI think the above link will point you in a closer direction. There are some caveats with select boxes apparently...if you're up to trying to see what the heck this code is doing, be my guest (supposedly something takes focus or precedence...I didn't dissect the code to understand it):
http://saloon.javaranch.com/cgi-bin/ubb/ul...20&t=006204
Kenny Pollock
Jul 22 2006, 08:12 PM
I couldn't get anything working... I hate working with JavaScript!!!
GreenElephants example worked for me once, and after I started incorporating it, it stopped. I've triple checked everything, it should be working!
Kenny Pollock
Jul 26 2006, 03:35 AM
*bump*
Brendon Koz
Jul 26 2006, 04:02 AM
Having the JS without the accompanying HTML doesn't help a lot of us to figure out what's wrong. I personally like to debug when I don't know a language like the back of my hand - JavaScript goes under that category.

If the data from the files are somewhat private, dummy data using the same scheme should work.

...if it's truly that important to you. Just zip it all up and upload it.
Kenny Pollock
Jul 26 2006, 05:06 AM
You got a PM! I would post the code, but it needs to use the db for the data, so it wouldn't work right.
Brendon Koz
Jul 26 2006, 02:07 PM
*.sql in attachment.
Brendon Koz
Jul 28 2006, 02:13 AM
FIXED.
GreenElephant led you astray accidentally:
CODE
*********.txt = *******;
It's
text, not
txt.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.