?
Solved

how to assign a listbox-label to a hidden field

Posted on 2003-02-27
10
Medium Priority
?
231 Views
Last Modified: 2012-08-13
I need to assign a listbox-label to a hidden field. I know how to get the value from the listbox. For example i use a js-function

<SCRIPT LANGUAGE=javascript>
<!--
function getSelectedValue()
{
iSelected=document.form1.sparte.selectedIndex
lblValue=document.form1.sparte[iSelected].text

return lblvalue
}
//-->
</script>

Here i get my value. But how do i insert this value into a hidden field. I probably need something like onsubmit to trigger the assignment of the value.
Any help appreaciated.
0
Comment
Question by:Chillipowder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 

Expert Comment

by:newbieME
ID: 8033753
Okay so u got ur label value from the listbox..but does that work?? i would normally use
lblValue = document.form1.sparte.options[iSelected].name
or something similar....but i am kinda new to javascripts myself so maybe urs does work...now to insert that value to a hidden field, u first make the hidden field like the following

<input type="hidden" name="banzai" value="">

and then to insert, use javascript command like

document.form1.banzai.value = getSelectedValue();

i hope i got this right....... O.O
0
 
LVL 39

Expert Comment

by:appari
ID: 8033756
try this

<SCRIPT LANGUAGE=javascript>
<!--
function getSelectedValue()
{
iSelected=document.form1.sparte.selectedIndex;
lblValue=document.form1.sparte[iSelected].text;

document.form1.hdnConName.value = lblvalue;

return lblvalue
}
//-->
</script>


replace hdnConName with your hidden control name.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8033761
You just about have it. Let's say that the name of the hidden field is strHidden, then you would set the value like:

document.form1.strHidden.value = getSelectedValue;

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8033769
I would call the function with the onChange event of the sparte control, that way the hidden field would always be up to date.

Fritz the Blank
0
 
LVL 7

Expert Comment

by:cubrovic
ID: 8033893
if you have a
<form name="myform" onsubmit="sub()" ... >
...
<input type="hidden" name="FHide" />
...

</form>

and the code is

function sub() {
var c = getSelectedValue()
document.forms["myform"].elements["FHide"].value = c
}
0
 

Author Comment

by:Chillipowder
ID: 8034031
I tried the solution with the onchange. But in the source-code of the page i couldnt find the value from the selected index. Somehow its not working.
<SCRIPT LANGUAGE=javascript>
<!--
function getSelectedValue()
{
iSelected=document.form1.sparte.selectedIndex
lblValue=document.form1.sparte[iSelected].text

document.form1.strHidden.value = lblvalue;
return lblvalue
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" class="adinhalt">
<p class="inhalt">Hersteller Dusy ist in folgenden Sparten vertreten:<br>
</p>
<table width="250" border="0" cellspacing="5" cellpadding="0">
  <tr valign="top">
    <td width="93" align="left" class="header">Sparte</td>
  </tr>
 
  <tr>
    <td width="93"><img src="../images/spacer.gif" width="1" height="10"><span class="inhalt">Einrichtung</span></td>
  </tr>
  <tr>
    <td height="1" width="93"></td>
  </tr>
 
  <tr>
    <td width="93"><img src="../images/spacer.gif" width="1" height="10"><span class="inhalt">Kabinettware</span></td>
  </tr>
  <tr>
    <td height="1" width="93"></td>
  </tr>
 
</table>
<form name="form1" method="POST" action="/stopp/admin/herstellersparte_view2.asp?herstkey=2">
  <p><span class="inhalt">Hersteller folgender Sparte </span>
    <select name="sparte" onchange="getSelectedValue()">
      <option selected>Bitte w&auml;hlen</option>
     
      <option value="1" >Kabinettware</option>
     
      <option value="2" >Kabinettzubehör</option>
     
      <option value="3" >Kosmetik</option>
     
      <option value="4" >Kämme</option>
     
      <option value="5" >Bürsten</option>
           
    </select>
    <input type="submit" name="Abschicken" value="zuordnen">
    <br>
    <input type="hidden" name="herstkey" value="2">
    <input type="hidden" name="herstname" value="Dusy">
    <input type="hidden" name="strHidden" value="">
  </p>
  <input type="hidden" name="MM_insert" value="true">
</form>
</body>
</html>
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 200 total points
ID: 8034085
Try this:

<HTML>
<HEAD>
<SCRIPT LANGUAGE=javascript>
<!--
function getSelectedValue(intSelected)
{
document.form1.strHidden.value=document.form1.sparte[intSelected].text

alert(document.form1.strHidden.value)
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" class="adinhalt">
<p class="inhalt">Hersteller Dusy ist in folgenden Sparten vertreten:<br>
</p>
<table width="250" border="0" cellspacing="5" cellpadding="0">
 <tr valign="top">
   <td width="93" align="left" class="header">Sparte</td>
 </tr>
 
 <tr>
   <td width="93"><img src="../images/spacer.gif" width="1" height="10"><span class="inhalt">Einrichtung</span></td>
 </tr>
 <tr>
   <td height="1" width="93"></td>
 </tr>
 
 <tr>
   <td width="93"><img src="../images/spacer.gif" width="1" height="10"><span class="inhalt">Kabinettware</span></td>
 </tr>
 <tr>
   <td height="1" width="93"></td>
 </tr>
 
</table>
<form name="form1" method="POST" action="/stopp/admin/herstellersparte_view2.asp?herstkey=2">
 <p><span class="inhalt">Hersteller folgender Sparte </span>
   <select name="sparte" onchange="getSelectedValue(this.selectedIndex)">
     <option selected>Bitte w&auml;hlen</option>
     
     <option value="1" >Kabinettware</option>
     
     <option value="2" >Kabinettzubehvr</option>
     
     <option value="3" >Kosmetik</option>
     
     <option value="4" >Kdmme</option>
     
     <option value="5" >B|rsten</option>
         
   </select>
   <input type="submit" name="Abschicken" value="zuordnen">
   <br>
   <input type="hidden" name="herstkey" value="2">
   <input type="hidden" name="herstname" value="Dusy">
   <input type="hidden" name="strHidden" value="">
 </p>
 <input type="hidden" name="MM_insert" value="true">
</form>
</body>
</html>

Fritz the Blank
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8034088
You will just want to get rid of the line:

alert(document.form1.strHidden.value)


I just put that in there so that you will see that the code is working.

Fritz the Blank
0
 

Expert Comment

by:newbieME
ID: 8034127
did u take a look at my suggestion??
0
 

Expert Comment

by:newbieME
ID: 8034142
oh nevermind..i am a foo
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question