Forums

ASP

This topic is locked

Append constant value to dynamic value

Posted 14 Sep 2004 09:15:07
1
has voted
14 Sep 2004 09:15:07 Charles Knight posted:
How do I append a static value to a dynamic value ?
I have my dropdown box:

<option value="<%=(rsDb.Item("id".Value)%>"><%=(rsDb.Fields.Item("id_name".Value)%></option>

I want to a add a space and a dash (-) to end of the id result.

If i try this:

<option value="<%=(rsDb.Item("id".Value)%>" - ><%=(rsDb.Fields.Item("id_name".Value)%></option>

(note the space dash space in the end of the first db statement)<i></i>

I get the space and dash I require, but when I submit the form I get this error:

Syntax error (missing operator) in query expression '112 -'.

Anyone any suggestions on how it should be done

Replies

Replied 14 Sep 2004 10:51:46
14 Sep 2004 10:51:46 Lee Diggins replied:
Hi

Try these, either will do the job:

&lt;option value="&lt;%=(rsDb.Item("id".Value & " - "%&gt;"&gt;&lt;%=(rsDb.Fields.Item("id_name".Value)%&gt;&lt;/option&gt;
&lt;option value="&lt;%=(rsDb.Item("id".Value)%&gt; - "&gt;&lt;%=(rsDb.Fields.Item("id_name".Value)%&gt;&lt;/option&gt;


Digga

Sharing Knowledge Saves Valuable Time!!!
Replied 14 Sep 2004 11:59:59
14 Sep 2004 11:59:59 Charles Knight replied:
Both those answers givew this error:

Microsoft JET Database Engine error '80040e14'

Syntax error (missing operator) in query expression '112 -'.

/admin/machine_details_add.asp, line 196


Line 196 is part of the execute insert code
Replied 14 Sep 2004 12:03:52
14 Sep 2004 12:03:52 Charles Knight replied:
Doh
Should have pointed out that this dropdown is controlled by an onChange script:

&lt;script language="JavaScript"&gt;&lt;!--
function onChange() {
var Current =
document.form.id.selectedIndex;
document.form.ref_no.value =
document.form.id.options[Current].value;
}
//--&gt;&lt;/script&gt;

should I append this to have the space dash space after the vaule ?

If so, how would I do it ?
Replied 14 Sep 2004 12:21:20
14 Sep 2004 12:21:20 Lee Diggins replied:
Hi

The error is coming back from Access so the " - " is being passed as an operator 'minus', take out the " - " and try it again.

Let me know how you get on.

Digga

Sharing Knowledge Saves Valuable Time!!!
Replied 14 Sep 2004 12:29:09
14 Sep 2004 12:29:09 Charles Knight replied:
Without the " - " it works fine, its old code which I'm trying to enhance.
The client see a dropdown list of items. They select one and the onChange script get the value for the item and puts it into a text box. Id like the number to be followed by a space, then dash, then space.
If I use the onchange function it drops the value in OK and I can manually add the space dash space, plus what ever else and the record inserts OK.
When I putting the S-D-S anywhere else I get the error.
Replied 14 Sep 2004 12:58:08
14 Sep 2004 12:58:08 Lee Diggins replied:
Hi

If the field in the db is numeric then you will not be able to add the S-D-S to the value of the field as it's not a number.

Not sure exactly what the problem is, need more info and your code.

Digga

Sharing Knowledge Saves Valuable Time!!!
Replied 14 Sep 2004 13:08:07
14 Sep 2004 13:08:07 Charles Knight replied:
There's alot going on, on this page, but all works fine apart from this bit.
As I said earlier if I manually add the s-d-s after the onchange has done its bit it works fine.
By the way the db field is set to text.

Can post the entire page here if you like or I can send it to you.
Replied 14 Sep 2004 13:26:17
14 Sep 2004 13:26:17 Lee Diggins replied:
Hi

Send it to me and the javascript too. I might get to look at I today if lucky.

Digga

Sharing Knowledge Saves Valuable Time!!!
Replied 22 Sep 2004 12:21:07
22 Sep 2004 12:21:07 Lee Diggins replied:
Nice, very nice.

Thanks

Digga

Sharing Knowledge Saves Valuable Time!!!
Replied 13 May 2006 18:16:33
13 May 2006 18:16:33 Malcolm X replied:
Can anyone elaborate on how to use this?

&lt;script language="JavaScript"&gt;&lt;!--
function onChange() {
var Current
Current = document.form_name.db_item_from.selectedIndex;
document.form_name.db_item_to.value =
document.form_name.db_item_from.options[Current].value + " - "; } //--&gt;&lt;/script&gt;

Do I need to alter it to suite my database?

MAlly.
Replied 13 May 2006 18:18:25
13 May 2006 18:18:25 Malcolm X replied:
I would like to use this same code as I am getting the same error message.

I beleive that the error is coming up because the conflict of text and numberic fields in an update form to a database.

Replied 14 May 2006 04:05:37
14 May 2006 04:05:37 Charles Knight replied:
Bit hard to explain as this was quite a while ago, but basically the idea for me was to take the category ID from one db table (generated earlier by an insert page to create a new catergory ID) and place into another field in another table and with a - at the end.

Example: the bit in brackets is the colour-ID and the colour is called colour-name. All these are in table called "colours".
Red (1)
Yellow (2)
Blue (3)
Green (4)


In table "machine" I had a drop down box called colour-choice which showed the colur-name fromms from "colours" table. The client chose which colour they wanted from the drop down and it was inserted into a field in "machine" called colour. In my case I wanted to add a dash and then a space so the client could then add some more text. The final output was something like:
Red - Matt or Green - Metalic, the matt and metalic bits are what the client added manually.
Hope this make sence.

So how to do it:
Create a table for the colours and populate it, then a table for the finished result.

On the form page which is going to get the values from the colours table and put into the finished table add this script:

&lt;script language="JavaScript"&gt;&lt;!--
function onChange() {
var Current
Current = document.FormName.colour-name.selectedIndex;
document.FormName.colour.value =
document.FormName.colour-name.options[Current].value + " - "; } //--&gt;&lt;/script&gt;





&lt;select
name="colour-choice"
onChange="onChange()"
&gt;
&lt;%
While (NOT rsColoursTable.EOF)
%&gt;
&lt;option value="&lt;%=(rsColoursTable.Fields.Item("colour-ID".Value)%&gt;"&gt;&lt;%=(rsColoursTable.Fields.Item("colour-name".Value)%&gt;&lt;/option&gt;
&lt;%
rsColoursTable.MoveNext()
Wend
If (rsColoursTable.CursorType &gt; 0) Then
rsColoursTable.MoveFirst
Else
rsColoursTable.Requery
End If
%&gt;
&lt;/select&gt;


Like I said, it was a while ago so forgive me if I made any mistakes.

Let me know how you go, if you struggle I'll make a test page maybe.

Reply to this topic