Solved

Form submit: Ignoring value property as formfield data

Posted on 2003-11-12
5
315 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Do you want to insert HTML5 video into your site? This is the tutorial how to do so. What are the main advantages of HTML5 video? 1) Have good compression, good image quality, and low decode processor use. 2) It is royalty-free 3) It is easi…
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 how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 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

8 Experts available now in Live!

Get 1:1 Help Now