[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Form submit: Ignoring value property as formfield data

Posted on 2003-11-12
5
Medium Priority
?
325 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
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)
Suggested Courses

829 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