473,323 Members | 1,589 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,323 software developers and data experts.

a more compact script?

chunk1978
224 100+
hi there,

i have a few rather long winded functions in my javascript, which i'm assuming could be shrunk somehow, and would like to know if someone could suggest a way to make the code more compact...

the following function allows a select menu to populate a text field according to their values. i'd like to know if there's an easier, more compact way of writing this because i have about 600 lines like this on my form :-/

thanks in advance

Expand|Select|Wrap|Line Numbers
  1. function AddHiddenPrint(val)
  2.     {
  3.     if (val=="4x6_0"){
  4.     document.IMAGECtrlForm.hidden4x6.value = "";}
  5.     if (val=="4x6_1"){
  6.     document.IMAGECtrlForm.hidden4x6.value = "1";}
  7.     if (val=="4x6_2"){
  8.     document.IMAGECtrlForm.hidden4x6.value = "2";}
  9.     if (val=="4x6_3"){
  10.     document.IMAGECtrlForm.hidden4x6.value = "3";}
  11.     if (val=="4x6_4"){
  12.     document.IMAGECtrlForm.hidden4x6.value = "4";}
  13.     if (val=="4x6_5"){
  14.     document.IMAGECtrlForm.hidden4x6.value = "5";}
  15.     if (val=="4x6_6"){
  16.     document.IMAGECtrlForm.hidden4x6.value = "6";}
  17.     if (val=="4x6_7"){
  18.     document.IMAGECtrlForm.hidden4x6.value = "7";}
  19.     if (val=="4x6_8"){
  20.     document.IMAGECtrlForm.hidden4x6.value = "8";}
  21.     if (val=="4x6_9"){
  22.     document.IMAGECtrlForm.hidden4x6.value = "9";}
  23.     if (val=="4x6_10"){
  24.     document.IMAGECtrlForm.hidden4x6.value = "10";}
  25.     if (val=="4x6_11"){
  26.     document.IMAGECtrlForm.hidden4x6.value = "11";}
  27.     if (val=="4x6_12"){
  28.     document.IMAGECtrlForm.hidden4x6.value = "12";}
  29.     if (val=="4x6_13"){
  30.     document.IMAGECtrlForm.hidden4x6.value = "13";}
  31.     if (val=="4x6_14"){
  32.     document.IMAGECtrlForm.hidden4x6.value = "14";}
  33.     if (val=="4x6_15"){
  34.     document.IMAGECtrlForm.hidden4x6.value = "15";}
  35. }
  36.  
Feb 15 '07 #1
2 954
dmjpro
2,476 2GB
plz rewrite the function like ....

function AddHiddenPrint(val)
{
try
{
document.IMAGECtrlForm.hidden4x6.value = val.substring(val.indexOf('_')+1);
}catch(err)
{
alert(err.description);
}
}

give me the result
welcome in advance

i am online
Feb 15 '07 #2
acoder
16,027 Expert Mod 8TB
One possibility:
Expand|Select|Wrap|Line Numbers
  1. function AddHiddenPrint(val) {
  2.     document.IMAGECtrlForm.hidden4x6.value = val.replace(/4x6_/,"");
  3. }
  4.  
Feb 15 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

35
by: Mike MacSween | last post by:
Is it?
13
by: James Franklin | last post by:
Hi, I have a number of databases in A2K, written on different machines with different installations of Office. I have found that compacting a database while it is open regularly fails, seemingly...
13
by: Larry L | last post by:
Access is noted for bloating a database when you add and delete records frequently. I have always had mine set to compact on close, and that works great. Now after everyone's advice I split my...
7
by: me | last post by:
i run a script which compacts a backend mdb at midnight when no one is connected to the backend. I compact it on the server. But this means that we need an extra license for Office to have it...
2
by: Greg Strong | last post by:
Hello All, I've written code in a test database with test data. Everything seems to be working except compact database in VB code per http://www.mvps.org/access/general/gen0041.htm. The reason I...
6
by: MLH | last post by:
I just used Tools / Database Utilities / Compact Database in Access 97 for the first time. Unlike Access 2.0, it does not ask me to furnish a filename for it to compact into. It just launched...
5
by: SheldonMopes | last post by:
Here is my situation:I have several Access database projects that all keep their back-end data in a directory on a server. I would like to have a small Access application that could open each .mdb...
5
by: bob | last post by:
Hi Using 2003 - targeting the compact framework (c#), but would like to do most development using the full.net (manually leaving out stuff not in the compact framework). Q. Trying to find a...
3
by: jonnyboy | last post by:
Hello again, Thanks to Scott for helping out with my last query. I've had a good look round but I can't find anything that carries out what I'm trying to do. I've got a function that imports...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: 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.