473,322 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Saving selection in drop-down lists via JavaScript after page reload?

Hi all,

I can't find an answer to my quesiton anywhere.

Given a drop-down list with USA states and other text fields I pass
this information for further processing via PHP. If any of the required
fields is empty, the PHP script would return an error and reload the
form page asking to fill out those fields. All entered information is
saved... except for the drop-down list selection. I tried to write a
Javascript function which is echoed by PHP, but interpolation of PHP
variables in the Javascript section gives a syntax error message in
Javascript.

The PHP script returns, e.g., an "AL" string for Alabama. How can I
save user selection (Alabama) using JavaScript in this case?

Would appreciate any reply to my question.

Thanks!

Dshan

Jun 19 '06 #1
3 3129
ds***@web.de wrote:
Hi all,
Hi,

I can't find an answer to my quesiton anywhere.

Given a drop-down list with USA states and other text fields I pass
this information for further processing via PHP. If any of the required
fields is empty, the PHP script would return an error and reload the
form page asking to fill out those fields. All entered information is
saved... except for the drop-down list selection. I tried to write a
Javascript function which is echoed by PHP, but interpolation of PHP
variables in the Javascript section gives a syntax error message in
Javascript.
In that case you made a syntax error.
Just look at the source from your browser and see what PHP wrote and why it
is bad syntax.
Remember that PHP has NOTHING to do with Javascript, except for the fact it
has produced it.
Your JS should be syntactically allright, then the browser will execute it.
Simple as that.

The PHP script returns, e.g., an "AL" string for Alabama. How can I
save user selection (Alabama) using JavaScript in this case?
that can be done in many ways.
You can print the SELECTED from PHP in case you found the state.

First look at the source, and fix the syntax error (Use firefox if you need
debugging.)

Regards,
Erwin Moller
Would appreciate any reply to my question.

Thanks!

Dshan


Jun 20 '06 #2
Erwin Moller
<si******************************************@spam yourself.com> wrote in
news:44***********************@news.xs4all.nl:
ds***@web.de wrote:
Hi all,


Hi,

I can't find an answer to my quesiton anywhere.

Given a drop-down list with USA states and other text fields I pass
this information for further processing via PHP. If any of the
required fields is empty, the PHP script would return an error and
reload the form page asking to fill out those fields. All entered
information is saved... except for the drop-down list selection. I
tried to write a Javascript function which is echoed by PHP, but
interpolation of PHP variables in the Javascript section gives a
syntax error message in Javascript.


In that case you made a syntax error.
Just look at the source from your browser and see what PHP wrote and
why it is bad syntax.
Remember that PHP has NOTHING to do with Javascript, except for the
fact it has produced it.
Your JS should be syntactically allright, then the browser will
execute it. Simple as that.

The PHP script returns, e.g., an "AL" string for Alabama. How can I
save user selection (Alabama) using JavaScript in this case?


that can be done in many ways.
You can print the SELECTED from PHP in case you found the state.

First look at the source, and fix the syntax error (Use firefox if you
need debugging.)


Rather than use JS, I would do this with php alone. Ust use php to write
the options for the select control. As php is looping through all the
states, a php "if" statement can determine if this state has been
selected, and include the "selected" for this option.
Jun 20 '06 #3

Erwin Moller wrote:
In that case you made a syntax error.
Just look at the source from your browser and see what PHP wrote and why it
is bad syntax.
Remember that PHP has NOTHING to do with Javascript, except for the fact it
has produced it.
Your JS should be syntactically allright, then the browser will execute it.
Simple as that.
that can be done in many ways.
You can print the SELECTED from PHP in case you found the state.

First look at the source, and fix the syntax error (Use firefox if you need
debugging.)

Regards,
Erwin Moller

Thank you Erwin and Jim,

In a test file (without PHP) JS worked fine, I don't know exactly where
the problem was.

What I did, I fixed the problem by creating a PHP array of states,
e.g., "TX" => "Texas", and made a loop like this:

echo "<select name=state class=dropdown>";
foreach($states as $key => $value){
if($key == $rt['state']){
$selected="selected";
}
else{
$selected="";
}
echo"<option value=$key $selected>$value</option>";
echo "</select>"

Thank you again for your replies!

Regards,

Dshan

Jun 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Martin Karlsson | last post by:
Hi guys, Does anyone know how I can restore a selection created with createRange()? The problem is that I have a function that opens a new window with window.open() which of course makes the...
16
by: Bernd Hohmann | last post by:
Hi there, we're currently convert an old ISAM application to Java and DB2. Among the load of problems we found the reports which have user selections like "select all data between mm/yyyy and...
0
by: Robin Tucker | last post by:
Hi there, I have a list box (just happens to be owner draw). When I select multiple items using the CTRL key, the items I have selected become highlighted (obviously). Now, when I click on one...
4
by: rroman | last post by:
I have a drop downList being populated by a dataSet. My dataSet has the folliwing fields: (id, usersName, emailAddress). My dropDownList has the DataTextField set to usersName and the...
18
by: TORQUE | last post by:
Hi, Im wondering if anyone can help me with a problem. I have a form with more than 50 unbound fields. Some of the fields will be blank from time to time. This seems to be where im having...
2
by: Kannan | last post by:
Hi, I am trying to save Inbox selected message in C: I have used following code string SavedMessage = "C:\\AIA\\Message\\"; string strSaveName = "Test.msg"; Outlook._Application olApp = new...
3
by: NoDozing | last post by:
Trying load an embedded object to the clipboard and then save it to a file. When I try and save to the file, I'm getting a "Object reference not set to an instance of an object". I've marked the line...
3
by: Hartmut Dippon | last post by:
Hi all, I hope somebody can help me with following problem: I have an application where I can drag&drop files/dirs from within explorer onto my form. If multiple files/dirs are selected I...
1
by: darrel | last post by:
Good day! i just want to ask if their is someone who can teach on how i can save records, I'am using ADODB connection... it like this, my system is a time, subject and room scheduling system, all the...
3
omerbutt
by: omerbutt | last post by:
hi there i have a tbl in db which has following fields table name:stock id_no(primary key...autono) part_name(text) price(currency) now i have an asp and htmlbased form in which i have made a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.