?
Solved

Form submit: Ignoring value property as formfield data

Posted on 2003-11-12
5
Medium Priority
?
321 Views
Last Modified: 2010-04-09
Hello,

My form has a dropdown with x options each with a value property assigned. The <option> tags value property is used by a javascript function to display the content of the value in another formfield.
The dropdown is a "codelist" comprised of digits that each equal to a string (ie a zipcode tabel).

Now, when a user clicks submit, the data passed from the dropdown formfield is the content of the value property. As the content of the value property is just a textstring, the form processing page gets incorrect information from the form (the form needs the digits, not the matching text expression).

My question is thus: Is there a way to tell a form to process the actual option instead of the option's value property?

The alternative I thought of is removing the option's value property through javascript before form_submit, but I'd really like to keep my javascript to a minimum (theres allready way too much code on the page :-)

best regards,
Morten Kirsbo
0
Comment
Question by:Kirsbo
[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
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:Dean OBrien
ID: 9730926
Why not have the value = to the name of the opption.

<form id='form1'>
.....
     <option id='opt1' value='10101010'>10101010</option>
....
</form>

Easynow

0
 

Author Comment

by:Kirsbo
ID: 9730959
Because

"
The <option> tags value property is used by a javascript function to display the content of the value in another formfield.
The dropdown is a "codelist" comprised of digits that each equal to a string (for example a zipcode tabel).
"

the value property is used for displaying in another textfield.

/MK
0
 
LVL 12

Accepted Solution

by:
Dean OBrien earned 500 total points
ID: 9731194
Dont think you can process the option instead of the value.  I would recommend changing the value before submitting.

<script>
function changeB4submit()
{
  select1.value = document.getElementById('select1').innerHTML
  form1.submit()
}
</script>

-----------

<form id='form1'>
<select>
<option id="select1" value="whatever">10101010</option>
</select>
<input type="button" onclick="changeB4submit()">
</form>

Easynow
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9731793
function getSelectText(selObj){
    return selObj.options[selObj.selectedIndex].text;
}

<form....>
<select name="something" onChange="this.form.test.value = getSelectText(this);">
<option></option>
<option value="123">TEST1</option>
<option value="456">TEST2</option>
<option value="789">TEST3</option>
<option value="012">TEST4</option>
</select>

<input type="text" name="test">
</form>

What this does is get the option text and puts the text for the value of the test field.
0
 

Author Comment

by:Kirsbo
ID: 9739601
solved it like this

var sel_col=document.getElementsByTagName("select") //Create collection of <select>'s

for (i = 0; i < sel_col.length; i++){
sel_col(i).options[sel_col(i).selectedIndex].value=
sel_col(i).options[sel_col(i).selectedIndex].innerText; }

0

Featured Post

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

752 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