Solved

Form submit: Ignoring value property as formfield data

Posted on 2003-11-12
5
319 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 250 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Technology Resume 7 84
Link Anchor Not working 9 65
Html date format 9 28
Displaying Text in Columns in HTML 3 30
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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 elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
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 …

739 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