Jump to content

contact form dropdown value


turkspartan

Recommended Posts

Hey guys. At http://abautoglass.net/contact-us/ I have a form with dropdowns. The dropdowns populate car information. The trim section works fine, but when I email the form, instead of showing the text in the trim section, it emails me a number. See code below I got from Firebug.

<option value="44387">2.0T Premium</option>

So instead of the trim section emailing me 2.0T Premium, it emails me the value section. How can I fix this?

Thanks

Link to comment
Share on other sites

You can use Javascript to look through each element of the dropdown and modify its value.

var selectObject = [reference to dropdown element here];
var options = selectObject.getElementsByTagName("option");

for(var i = 0; i < options.length, i++) {
  options[i].value = options[i].text;
}

Of course, doing this will mean you lose the actual ID of the car. There are other more complicated solutions for if you need both the ID and the name.

Link to comment
Share on other sites

I assume by "dropdown" you are talking about a select, and not a datalist which behaves quite differently and not the save across all browsers.

 

Instead of sending the value of the option, you need to send the text of the option.

The easiest way is probably to add a hidden input

<input type="hidden" id='selVal" name="selVal">

then in the scripting:

 

SEL=document.getElementById('Idofselect');

target=document.getElementById('selVal');

target.value=SEL.options[sEL.selectedIndex].text;

 

You can trigger the code as part of whatever client side validation you are doing, or just add an event listener to the select triggered from the chage event

Link to comment
Share on other sites

Hacking the page by overwriting after it is loaded will work, but you need to understand that you will be making the page worse for future maintenance, reliability, and efficiency. If you you have the url to the script you should be able to download it. though if the jquery is minified it might be a little difficult to do anything with it. Even if you cannot directly download it, it should be in your cache.

 

If you have the coding skills to fix it, then you might want to consider getting rid of the script and writing your own. Anything that is so restrictive that you cannot do simple changes without jumping through hoops is not a helpful tool, and the more you hack around it, the close you get to it crashing.

Link to comment
Share on other sites

You don't have to modify the original script, you just have to write some Javascript to change the page after the other script has finished running.

I am not the greatest at java. Can you tell me how I can take the above code you mentioned and connect it to that contact form? If it won't be trouble ofcourse. Thanks so much for your help! I need to get this done and I can't figure it out.

Link to comment
Share on other sites

So you plan use select and alll its options, then clone to create another select with alll options with values and text swapped round, mark selected option from first to second, then collect that value later on?????.

 

IS it not more practical to follow post #5 and copy selected option TEXT not! value to a HIDDEN input and use that instead of select value. It is completely separate from select option, it will still be submitted, but you will use hidden input to retrieve text value, and if you wish the id value from select dropdown.

Link to comment
Share on other sites

Okay thanks for all the help guys. I downloaded the script I was using to put all of the data into the SELECT field.

 

Than I switched the line of code from this:

options += '<option value="' + trims.model_id + '" '+s+'>' + trim_display + '</option>';

 

to this:

options += '<option value="' + trim_display + '" '+s+'>' + trim_display + '</option>';

 

So now both the text and value are set to the Trim names.

 

Thanks guys!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...