Forums

problem: trying to get the selected value from the select

giladl1 24 Oct, 2013
hi,
I have a simple form in which there is a submit button and and a select (dropdownlist).
I need to get the selected value/index from the select and it always gives me the first value or the index 0. any suggestions what is wrong ?
thanks!
this is the code of the form:

<table border="1"><tr><td>
<select size="1" class="" title="" type="select" id="input_select_1">
<option value="1,4,#,#,#,#,1,2">תמיכה טכנית בטלויזיה</option>
<option value="1,4,#,#,#,#,1,1">תמיכה טכנית בשלט</option>
</select></br>
<input name="input_submit_tv" class="" value="הזמן שיחה" type="submit" />
</td>
</tr>
</table>




this is the javascript I use to get the values:

window.addEvent('domready', function() {

var x=document.getElementById("input_select_1").selectedIndex ;
alert(x);
var y=$('input_select_1').value;
alert(y);
GreyHead 24 Oct, 2013
Hi giladl1,

I think that your code is behaving correctly. The JavaScript is set to run when the page loads and the first option is selected then.

Bob
giladl1 24 Oct, 2013
but the "load js" part is inside the "on submit" section and I want the selected data to be the data when the button is clicked.
GreyHead 24 Oct, 2013
Hi giladl1,

Adding it to the On Load event just means that it is loaded when the form is loaded (if you add it to the On Submit event then it will be loaded when the Thank You page is loaded.

If you want it to do something when the Submit button is clicked then you need to add it to the onClick event for the button. There are many examples here of code like that. Please try searching on addEvent.

Bob

PS Your select input doesn't have a name so won't submit anything to ChronoForms.
giladl1 26 Oct, 2013
after a lot of reading in other posts I understood how to get the correct values,but then got other problems. it seem that I have some basic missunderstanding-why does the next code works only the first time when I click the button,and in the next clicks nothing happens ?
the html stays the same.
the js code inside the load Js before the show html-both in the onload section:

var mySubmitButton,mySelect;
window.addEvent('domready', function() {
mySubmitButton=document.getElementById("input_submit_tv");
mySubmitButton.addEvent('click', startCall);//the big change in solving last problem
}); 
function display2(){
alert("display2");
}
function display(){
alert("display");
display2();
}
function startCall(){//here starts the click event
alert("startCall");
display();
}
GreyHead 26 Oct, 2013
Hi giladl1,

If the script stops working then there is probably a JavaScript error on the page.

Bob
giladl1 26 Oct, 2013
what do you mean "on the page"-where should I look for it ?
thanks
Gilad
GreyHead 26 Oct, 2013
Hi giladl1,

In the JavaScript Console of your browser Web Developer tools, click F12 in most browsers to see them.

Bob
This topic is locked and no more replies can be posted.