Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Macro substitution in javascript
Message
From
16/03/2002 11:46:01
 
General information
Forum:
Internet
Category:
Javascript
Miscellaneous
Thread ID:
00633553
Message ID:
00633749
Views:
22
>>If I got the clue right, [snip]

No, I got it wrong! You wanted VFP style macros... I though something in the line of #define's to save typing...

>I couldn't get the code to render the value of the variable. Document.write() would only write the var, not evaluate it. If a user selects Memphis Police Department in the dropdown, I want the MPD's address to populate the street number, street name and city fields for the associated row. I have each row's field names built dynamically. I guess I could prebuild the form with an array and handle it that way, but I was hoping there was some way to make the code a little tighter.

Your ckvar could be like this:
< script language="javascript" >
< !-- //
function ckvar (cDept, cIndex)
switch (cDept){
  case "1": 
     userform["strno"+cIndex].value = "201";
     userform["street"+cIndex].value = "Poplar";
     userform["city"+cIndex].value = "Memphis";
     break;
  case "2": 
     userform["strno"+cIndex].value = "201";
     userform["street"+cIndex].value = "Poplar";
     userform["city"+cIndex].value = "Memphis";
     break;
// other cases...
  }
// -->
and your select variable
< select size="1" name="D1" onchange="javascript:ckvar(this.value,'1');" >
  < option value="0">Make a Selection< /option>
  < option value="1">Bartlett Police Department< /option>
  < option value="2">Collierville Police Department< /option>
  < option value="3">Germantown Police Department< /option>
  < option value="4">Memphis Police Department< /option>
  < option value="5">Millington Police Department< /option>
  < option value="6">Shelby County Sheriff's Office< /option>
< /select>
(make sure extra spaces are removed and each option values are correct). Bear in mind that the way you are referencing the form object is not browser independent (don't know if that is a problem).
----------------------------------
António Tavares Lopes
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform