turkspartan Posted January 13, 2016 Share Posted January 13, 2016 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 More sharing options...
turkspartan Posted January 13, 2016 Author Share Posted January 13, 2016 The value section is being populated from car query api. So I cant change the value section. http://www.carqueryapi.com/documentation/getting-started/ Link to comment Share on other sites More sharing options...
turkspartan Posted January 13, 2016 Author Share Posted January 13, 2016 bump plz help. Link to comment Share on other sites More sharing options...
Ingolme Posted January 13, 2016 Share Posted January 13, 2016 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 More sharing options...
COBOLdinosaur Posted January 14, 2016 Share Posted January 14, 2016 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 More sharing options...
turkspartan Posted January 15, 2016 Author Share Posted January 15, 2016 Thanks guys, but I am not sure if this can be done. I do not have the script so I cant modify it. I just have the url to it, which is <script type="text/javascript" src="http://www.carqueryapi.com/js/carquery.0.3.4.js"></script> Will the above recommendations still work? I am not sure how to do it. Thanks! Link to comment Share on other sites More sharing options...
Ingolme Posted January 15, 2016 Share Posted January 15, 2016 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. Link to comment Share on other sites More sharing options...
COBOLdinosaur Posted January 16, 2016 Share Posted January 16, 2016 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 More sharing options...
turkspartan Posted January 16, 2016 Author Share Posted January 16, 2016 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 More sharing options...
turkspartan Posted January 17, 2016 Author Share Posted January 17, 2016 (edited) How about this. I make that SELECT hidden. And whatever they select in that first SELECT gets copied into another select that will work properly... I just dont know how to copy the options from one select to another. Edited January 17, 2016 by turkspartan Link to comment Share on other sites More sharing options...
dsonesuk Posted January 17, 2016 Share Posted January 17, 2016 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 More sharing options...
dsonesuk Posted January 17, 2016 Share Posted January 17, 2016 Another option is to combine text and id value together <option value="44387-2.0T Premium">2.0T Premium</option> Then using '-‘ as delimiter separate "44387" from "2.0T Premium" into array so you reference one or the other. Link to comment Share on other sites More sharing options...
turkspartan Posted January 17, 2016 Author Share Posted January 17, 2016 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now