...

View Full Version : Help with selecting strings in a select field...



dottedquad
01-20-2005, 10:59 PM
For example if the user selected New York and pressed the submit button php will do some checking and if an error came up it will hault and echo out the errors and keep the orginal information in the fields. I need to do this with a select field. I would like to use javascript because i think it would be easier then pulling info out of a database and outputting it. I already have a select field with the information and i just need it to select previous information. Except i have no clue how to code in javascript. Could anyone help me out?

Thanks,
Rich

Basscyst
01-20-2005, 11:09 PM
:confused: Could you elaborate? :confused:

What are these errors you are reffering to? At what point do you wish to revert to the prior selection. . .since js is clientside, and any function that would be run to check for these errors would already be loaded with the page, the selected option should already be retained. Your needs just really aren't clear.

Basscyst

dottedquad
01-21-2005, 02:35 AM
:confused: Could you elaborate? :confused:

What are these errors you are reffering to? At what point do you wish to revert to the prior selection. . .since js is clientside, and any function that would be run to check for these errors would already be loaded with the page, the selected option should already be retained. Your needs just really aren't clear.

Basscyst


Sorry for not elaborating better. I was in a rush when i posted before cause i had to get to work. Anyways, What i need to do is select the previous selection in the select field. Say the user selected New York and they hit the submit button I need something to automatically select New York or any other state when the form comes up again. Is this possible to do with Javascript?

Here's what i thought on how to do this: First when the page is submitted have javascript set a cookie with the value of the select field. Next when the page loads use javascript to read the cookie and have javascript automatically find and select that value in the select field. Just I have no clue where to get started with javascript.

-peace,
Rich

Kor
01-21-2005, 01:35 PM
Could be done using cookies, but you may consider that some users might restrict the cookies receiving, thus the best way is a server-side method.

dottedquad
01-23-2005, 03:46 AM
Could be done using cookies, but you may consider that some users might restrict the cookies receiving, thus the best way is a server-side method.

Alright well i did it an easier way:

function getstate() {
document.accounts.states.selectedIndex = <?php echo $_POST['states']; ?>;
}

<body onload="getstate()">

Kor
01-24-2005, 10:09 AM
Well yea... this is a server-side method, as I have suggested... :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum