Read on full site | Join TechSpot! (it's free) | Bookmark / Share this



Javascript for a HTML <select> possible?

RealBlackStuff
09-10-2004, 09:52 AM
Hello Javascript Gurus,

Is there a way to put the following HTML-coding into a Javascript file? (something.JS)

<SELECT NAME="Surname" CLASS="quoteform"><br>
<option selected>Select Surname
<option>Connolly
<option>Gallagher
<option>O'Brien
etc.
</select>

I have a webpage with photos of Family Crests and crested paraphernalia, each of which is only available in the (selectable) Surnames.

Crested items are available in different groups of names. Rather than having the same SELECT code under each photo, I would prefer to call up a Javascript, in which I can stick the complete selection.

Any sample-scripts greatly appreciated.

I searched the WWW intensively, but no samples found.

DigitAlex
09-10-2004, 10:51 PM
put all the HTML in a javascript variable like :

var a =
"some HTML" +
" some more HTML";

then do a

document.write(a);

in the place you wanna insert the HTML

Ad
09-10-2004, 10:51 PM
  

RealBlackStuff
09-11-2004, 12:41 PM
Thanks DigitAlex,
I'll try that out and let you know.
Sounds simple enough if it works!

RealBlackStuff
09-14-2004, 12:57 PM
That took a bit of fumbling, but this is the (working) result:

Create a "filename.js" with e.g. text:

<!-- Start

function dothis()
{
document.write('<SELECT NAME="surname" CLASS="quoteform">');
document.write('<option selected> Select');
document.write('<option>Allen ');
document.write('<option>Anderson ');
document.write('<option>Barrett ');
etc.
document.write('</select>');
}
dothis();
// End -->




And in the main HTLM source, you only need to enter something like this:


Surname:
<script language="JavaScript" src="filename.js"></script>

Post a reply, see related topics & more

Tip: Download Advanced SystemCare 3 Free - Clean, Repair, Protect & Optimize your PC.



 Top Technology News

TechSpot Blog: Disable Windows automatic check for solutions after a program crashes

Tech Tip of the Week: Unearth Region-Specific Windows 7 Themes

Samsung intros 2TB, eSATA-packing Story Station Plus external HDD

Gartner: PC shipments to grow 2.8% in 2009, revenue down 11%

Microsoft issues warning for IE6, IE7 security hole

LG X120 netbook to launch in the US for $180 with two-year AT&T contract

Intel's six-core Gulftown processor benchmarked months early

Another iPhone worm spotted, this time it's dangerous

More Tech News

  
 Software Downloads

FlashGot 1.2.0.9

RemoveIT Pro XT - SE 23.11.2009

Vuze (Formerly Azureus) 4.3.0.4

RemoveIT Pro v7 Enterprise 23.11.2009

Aloaha PDF Suite 3.9.172

Blindwrite Suite 6.3.1.5

RemoveIT Pro v7 Ultra 23.11.2009

More Downloads



Copyright © 1998-2009 TechSpot.com. TechSpot is a registered trademark. All Rights Reserved.