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

Form is set by me

I have a drop-down box. I also have a var with a value. I want the
value in the var to be displayed in the drop-down box. How can I do
this?

Thanks.

Scott
Jul 23 '05 #1
4 1023
Scott wrote:
I have a drop-down box. I also have a var with a value. I want the
value in the var to be displayed in the drop-down box. How can I do
this?


How should your var behave in regard to your dropdownbox? Is your
dropdownbox already populated with <option>'s, before the code is
invoked that would alter its content? Should the dropdownbox react on
events on the webpage to get new content?

Reading your question as it is stated, this basic code could be an
answer:

var myvar = "somevalue";
document.write('<select size=1 name=myselectbox>');
document.write('<option value="'+myvar+'">'+myvar+'</option>');
document.write('</select>');

Bart
Jul 23 '05 #2
Bart,
How should your var behave in regard to your dropdownbox? Is your
dropdownbox already populated with <option>'s, before the code is
invoked that would alter its content? Should the dropdownbox react on
events on the webpage to get new content?


I didn't get my message clear enough. My var already has a value. My
dropdownbox is already populated with <options>'s. What I want to know
is can my var be matched with the <option>'s directly and the <option>
get executed.

Scott
Jul 23 '05 #3
> I didn't get my message clear enough. My var already has a value. My
dropdownbox is already populated with <options>'s. What I want to know
is can my var be matched with the <option>'s directly and the <option>
get executed.


Well you still left a few things unspecified, but guessing at those,
this code should do the trick:

<html>
<head>
<!-- var already has value, I'm setting it here -->
<script language="javascript">
var myvar = "somevalue";
</script>
</head>
<body>
<!-- your dropdownbox with its options, set in html -->
<form action="somescript.cgi">
<select size="1" name="mybox">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</form>
<!-- now change contents of the box -->
<script language="javascript">
// empty the box
while (document.forms[0].mybox.options.length)
document.forms[0].mybox.options[0] = null;
// put var in the box
document.forms[0].mybox.options[document.forms[0].mybox.length]
= new Option(myvar, myvar);
// now set which option must be selected.
// required in NS4, and handy in IE when you want
// to select an option that doesn't come first
document.forms[0].mybox.selectedIndex = 0;
// now "execute" the dropdownbox: do you mean submitting the form?
// if so, uncomment this line:
// document.forms[0].submit();
</script>
</body>
</html>

Bart
Jul 23 '05 #4
Bart,

I came up with this. It works:

var str = window.location.search; // returns
'?text=language' from the URL
if (str != "") {
var temp = str.split('=');
for (i=1; i <= speclang.length; i++) { // goes through whole
language array
if (temp[1] == speclang[i]) break; // found
}
if (i > speclang.length) { // didn't find
alert(temp[1] + " was not found in the Mexican language list.");
return;
}
}
document.forms['Language'].selectname.selectedIndex = i; // make
dropdown box = passed language
languag(i); // update to specific language
}
Jul 23 '05 #5

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

Similar topics

3
by: John | last post by:
Dear all, It been more than 3 days I am trying to debug this program, I interpret it using activePerl and it is giving (perl -wc code_process.pl) no error syntax but when I put it online, change...
5
by: Richard Cornford | last post by:
I am interested in hearing opinions on the semantic meaning of FORM (elements) in HTML. I have to start of apologising because this question arose in a context that is not applicable to the...
4
by: Targa | last post by:
Trying to total some price fields in a form but doesnt work when all the referenced form fields dont exisit. This is for an invoice - pulled prom a database and the form doesnt always contain the...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
19
by: Raposa Velha | last post by:
Hello to all! Does any of you want to comment the approach I implement for instantiating a form? A description and an example follow. Cheers, RV jmclopesAThotmail.com replace the AT with the...
11
by: Jozef | last post by:
I have some old code that I use from the Access 95 Developers handbook. The code works very well, with the exception that it doesn't seem to recognize wide screens, and sizes tab controls so that...
5
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
6
by: Gary Miller | last post by:
Does anyone know how to detect a modeless form on closing by the form that invoked the modeless form? form.Show();
4
by: Alex Sibilev | last post by:
Hello, I have a really weird problem I've been trying to solve it without any luck for the last couple of hours :( I'm writing a "conference board" application (quite similar to ASP.NET...
5
by: ortaias | last post by:
I have a form which calls up a second form for purposes of data entry. When closing the data entry form and returning to the main form, things don't work as expected. When I return to the main...
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: 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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.