Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Javascript needed

Status
Not open for further replies.

NEveritt

MIS
Dec 30, 2002
25
GB
I would love to work out how to do this unaided, but I need to get this sorted quick, so would appreciate some help here:

I have been told I need a function to do this, so if someone could help me out.

I have a DB table with the following 3 fields:

ItemID, ItemName, ItemValue

The form is a drop down list (with entries from the DB), and a text box.

The drop down list is to show all the ItemName 's, and when one is selected, the ItemValue is then added into text box.

I have got this to work by using the Name & Value of the drop down list.

However I need to send the ItemID back to the DB to record their selection.

So I have nowhere else to put the ItemID in the drop down, so I have been told I need to do some JS to link whats selected to the ItemID.

Can anyone help?

Ask away with any questions

 
You don't necessarily need Javascript to do the selectbox part, although if you don't want to refresh the page, you may need if for filling the textbox with content. But for your specific question, you could have the "value" of the selectbox's options be a combination of the two things you need, separated by a character that will never end up in both - e.g.:
Code:
<option value="ItemID#ItemName">ItemValue</option>
Then in the routine that it called when the user chooses something, parse the value into its two parts (if it was PHP, for example, split("#",$value) would work nicely), put the first part into the database and the second part in the textbox.
 
>I would love to work out how to do this unaided
Change your handle or even keept it, no one is to know you work out aided.

But aided or not aided, you have to able to understand what is being advised---if you don't like it, no one is forcing anything on you.

You do not follow up the matter on your last thread. I think I had told you the value of the select-one element is being posted back to server. So you do not need to have the ItemID independently written to another textbox in the form. It is a simple split on the request.form("selectname") if it is by method post or a simple split on the request.querystring("selectname") if it is by method get. The [0] component be ItemID and [1] component by ItemValue if the value is scripted as "ItemID,ItemValue" where "comma" is a symbolic separator.
 
thanks for that, I will have a look at it, but I will need to do this with JS as I do not want to refresh the page.

so can anyone help?

N
 
I thought we were helping. I answered the question you had - combine the two values in the selection options' value attribute using a separator character.
I will need to do this with JS as I do not want to refresh the page.
I don't know what you mean by "this". You can't do it all with JS because you want to update your database (you haven't said what kind of database you have, but I assume it's something on your server). A client-side script (i.e. JS) cannot access a server-based database, so at some point you have to run code that is on the server. So if you don't want to refresh the page you have, you will have to call some other page - a hidden iframe or popup or something that will run PHP, ASP, etc. to update the database.

What environment are you using (what kind of server-side language do you normally use, what database do you have, etc.)? And what other specific questions do you have?
 
>as I do not want to refresh the page
But you have to show evidence you are well-prepared for the aj-thing not just I want this and I want that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top