Solved

Form submit: Ignoring value property as formfield data

Posted on 2003-11-12
5
317 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Javascript create file issue 4 60
Centered Image 2 27
Javasctipt 2 24
HTML5 save .Dat to server side 20 45
Introduction The Google Maps API offers various ways to draw dynamic and static maps.  Using a combination of PHP and JavaScript, you can draw active JavaScript maps that allow pan-and-zoom in the client browser window.  You can also draw "static" …
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…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

815 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now