Well, I think first you'd need to change the name of the <html:text> element
to something other than artist to avoid javascript confusion. The value for
artist will be posted to the server by the <html:select> object.


(watch for line breaks) 

<script language="JavaScript">
<!--
  function setArtist(control){
 
document.forms[0].artistReadout.value=control.options[control.selectedIndex]
.value;
  }
//-->
</script>


PullDown and text field:

<html:text property="artistReadout" size="40"/>
<html:select property="artist" onchange="setArtist(this);">
  <html:options collection="artist" property="value" labelProperty="label"/>
</html:select>


The javascript event you want to use in onchange, not onclick.

The syntax to pull the value out of a select list is a little convoluted.
The relevant javascript objects are (assuming a select element called
"mySelect"):

mySelect.options = an array of the option elements
mySelect.selectedIndex = the index of the selected element

mySelect.options[mySelect.selectedIndex].value = the value of the selected
option

Lee

-----Original Message-----
From: rgi [mailto:[EMAIL PROTECTED]]
Sent: Monday, December 03, 2001 5:59 AM
To: [EMAIL PROTECTED]
Subject: html:select and JavaScript problem


Hello struts-user,

  I want to write a selected element from a PullDown in a text form. I
  use a JavaScript funktion to do this. This funktion is excecuted
  when someone click on a element from the PullDown. (or perhaps not
  excecuted?)
  The problem is now, nothing is written in the text field.

JavaScript funktion in the header area:

<script language="JavaScript">
<!--
  function setArtist(artistStr){
    document.forms[0].artist.value=artistStr;
  }
//-->
</script>


PullDown and text field:

<html:text property="artist" size="40"/>
<html:select property="artist" onclick="javascript:setArtist(value);">
  <html:options collection="artist" property="value" labelProperty="label"/>
</html:select>



Have someone a idea to solve this problem???


-- 
Best regards,
 rgi                          mailto:[EMAIL PROTECTED]


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

Reply via email to