Jump to content

Recommended Posts

Posted
You can also use javascript to select something after your list is loaded. But I'm not sure if you're looking for this type of answer.

Yes...I will need something after the list is loaded. Mind showing me the code.

 

@TCH-Bruce

Heh, thats pretty much the same thing...Not what I was looking for...thanks for the reply anyway.

Posted

Those would be the two ways that I know of. For the javascript something close to:

 

><script>
Function DoThis() {yourformname.Auto_Name[optionname].select();}
</script>
<body onload(DoThis)>

 

You woule have to "name" everthing for Javascript to find this i.e. <form action="" name="yourformname""....>, <option value="Acura"> Acura </option>, etc.

 

If you wanted to have the form select an option depending on other input from another page, you could make the form page PHP. Pass a variable to the form page, then have php write that portion of the form.

Posted
LMAO good timing hu? Rock Sign

Nice...thank you so much.... Where did you get this source if I may ask..any good sites for nitpicky stuff like this.

 

the only site i usually use for javascript xhtml etc is w3schools.com. Its been adequate as a reference but I wouldn't mind using another one for other rare occassions.

Posted
Those would be the two ways that I know of. For the javascript something close to:

 

><script>
Function doThis() {yourformname.Auto_Name[optionname].select();}
</script>
<body onload(doThis)>

 

You woule have to "name" everthing for Javascript to find this i.e. <form action="" name="yourformname""....>,  <option value="Acura"> Acura </option>, etc.

 

If you wanted to have the form select an option depending on other input from another page, you could make the form page PHP. Pass a variable to the form page, then have php write that portion of the form.

ok...I spoke to soon...I was sure i would be able to get your code to work but i was wrong...forgive my ignorance....can you help me out...

 

can u implement your code on the sample form listed on this site.

http://www.w3schools.com/tags/tryit.asp?fi...tryhtml_select3

 

The below didn't work.

><html>
<script type="text/javascript" language="javascript" >
<!--
 function selectform() { testform.cars[audi].select(); }
-->
</script>

<body onload(selectform)>

<form name="testform">
<select name="cars">
 <option value="volvo">Volvo</option>
 <option value="saab">Saab</option>
 <option value="fiat">Fiat</option>
 <option value="audi">Audi</option>
</select>
</form>


</body>
</html>

Posted

This is how you might select a car:

 

<html>

<body>

<script>

function selectform(carnum) {

document.testform.cars.options[carnum].selected=1;

}

</script>

 

<form name="testform">

<select name="cars">

<option value="volvo">Volvo</option>

<option value="saab">Saab</option>

<option value="fiat">Fiat</option>

<option value="audi">Audi</option>

</select>

</form>

 

<script>

selectform(3);

</script>

 

</body>

</html>

 

 

With options, you have to treat them like arrays. The option count actually starts at 0, so even though "audi" is the 4th car, it's actually #3 in the list. The "volvo" would be #0.

 

I use this kind of logic all the time in my programs when retrieving data from a database to populate a form with a list selection.

 

Let me know if this is what you need. Send a PM to me if you want to get a quicker response from me.

 

Good luck!

Posted
This is how you might select a car:

 

<html>

<body>

<script>

function selectform(carnum) {

document.testform.cars.options[carnum].selected=1;

}

</script>

 

<form name="testform">

<select name="cars">

<option value="volvo">Volvo</option>

<option value="saab">Saab</option>

<option value="fiat">Fiat</option>

<option value="audi">Audi</option>

</select>

</form>

 

<script>

selectform(3);

</script>

 

</body>

</html>

 

 

With options, you have to treat them like arrays. The option count actually starts at 0, so even though "audi" is the 4th car, it's actually #3 in the list. The "volvo" would be #0.

 

I use this kind of logic all the time in my programs when retrieving data from a database to populate a form with a list selection.

 

Let me know if this is what you need. Send a PM to me if you want to get a quicker response from me.

 

Good luck!

Fantastic..I understand perfectly now. Thanks guys... So do you guys have any good sites to recommend to find little nitpicky stuff like this. Or are you just javascript gurus or what.

Posted

LOL

 

Ask a lot of questions, I even changed my user name at a support site after a while because I asked so many. (got bashfull)

 

 

I buy a good "for dummies book" to get started. I have Javascript, HTML, Perl etc for dummies. Then I get a good Bible, Que or Peachpit (or insert another) for the hard core stuff.

 

For good sites:

 

http://www.webmasterworld.com/

 

http://www.phpfreaks.com/forums

Posted

I use Javascript all the time.

 

There's a book from O'Reilly that I reference all the time. In fact, I did it this time too ... just to be sure. Found I was using "option" when I should have been using "options".

 

There's this other wierd thing that can happen too. You can accidentally try to reference a form before it's loaded. That's why the function for it is at the top, while the use for it is after the form.

 

I suppose you could do the "onLoad" to cover this, but I've never found those trustworthy for some reason.

 

Good luck with your project!

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...