HighDots Forums  

Teil in JS selbst bei Optionauswahl ändern

Javascript (German) Programmiersprache JavaScript. (de.comp.lang.javascript)


Discuss Teil in JS selbst bei Optionauswahl ändern in the Javascript (German) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
marc heiners
 
Posts: n/a

Default Teil in JS selbst bei Optionauswahl ändern - 04-05-2007 , 06:10 AM






Hallo zusammen!

Mit folgendem Code ändere ich bisher ein onclick-Event in Abhängigkeit einer
Option-Auswahl:

<script language="JavaScript">
function setLink (select, elementId) {
var link = document.getElementById(elementId);
if (link != null) {
link.href = select.options[select.selectedIndex].value;
}
}
....
....
<option value="javascript:sendEvent('playitem',1)"> Name 1 </option>
<option value="javascript:sendEvent('playitem',2)"> Name 2 </option>
<option value="javascript:sendEvent('playitem',3)"> Name 3 </option>
....
....
<a href="javascript:sendEvent('playitem',0)" id="linkId">



Wenn der User also eine andere Optionauswahl trifft, wird im Link der
gesamte JS-Code ausgetauscht. Da hier allerdings 2000 Namen bzw.
Optionauswahlen angeboten werden, möchte ich

<option value="javascript:sendEvent('playitem',1)"> Name 1 </option>

kürzen in

<option value="1"> Name 1 </option>

So spare ich löcker 60 kb pro Seitenaufruf. Das Problem ist, dass ich nicht
weiß, wie ich dem JS klar machen soll, dass es nicht den gesamten Link
austauschen soll, sondern nur die Zahl, die am Ende vorkommt. Kann mir
jemand dabei helfen?

Viele Grüße
Marc



Reply With Quote
  #2  
Old   
Torsten Robitzki
 
Posts: n/a

Default Re: Teil in JS selbst bei Optionauswahl ändern - 04-05-2007 , 07:36 AM






marc heiners wrote:

Quote:
Hallo zusammen!

Mit folgendem Code ändere ich bisher ein onclick-Event in Abhängigkeit einer
Option-Auswahl:

script language="JavaScript"
function setLink (select, elementId) {
var link = document.getElementById(elementId);
if (link != null) {
link.href = select.options[select.selectedIndex].value;
wie wäre es mit
link.href = "javascript:sendEvent(\'playitem\'," +
select.options[select.selectedIndex].value + ')'
?

mfg Torsten



Reply With Quote
  #3  
Old   
marc heiners
 
Posts: n/a

Default Re: Teil in JS selbst bei Optionauswahl ändern - 04-05-2007 , 08:40 AM



<wie wäre es mit
<link.href = "javascript:sendEvent(\'playitem\'," +
<select.options[select.selectedIndex].value + ')'
<?

Ich würde sagen gut. Ich würde sagen: ziemlich gut! :-)
Danke!

Gruß Marc



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.