...

View Full Version : combo box value not getting



coolumanga
06-22-2012, 05:30 PM
hi i have this coding

<script type="text/javascript">


function getCombo1(sel) {
var value = sel.options[sel.selectedIndex].value;

if(value = "Value1")
{

document.getElementById('t1').value =5;


}
}

</script>
<select id="combo1" onchange="getCombo1(this)">
<option value="">Select combo</option>
<option value="Value1">Text1</option>
<option value="Value2">Text2</option>
<option value="Value3">Text3</option>
</select>

<input name="" type="t1" />


i hear what i want to do is the when selecting combo box text1 text box will be 5


plz help me to do this


sample coding plzzzzzzzzzzz

WolfShade
06-22-2012, 05:41 PM
<input name="t1" id="t1" type="text" />

coolumanga
06-22-2012, 05:45 PM
<input name="t1" id="t1" type="text" />

still i cant solve the problem plese help me

coolumanga
06-22-2012, 05:46 PM
<input name="t1" id="t1" type="text" />

<script type="text/javascript">


function getCombo1(sel) {
var value = sel.options[sel.selectedIndex].value;

if(value = "Value1")
{

document.getElementById('t1').value =5;


}
}

</script>
<select id="combo1" onchange="getCombo1(this)">
<option value="">Select combo</option>
<option value="Value1">Text1</option>
<option value="Value2">Text2</option>
<option value="Value3">Text3</option>
</select>

<input name="t1" type="t1" />


plz help me to solve this

Philip M
06-22-2012, 06:31 PM
As wolfshade has told you, <input type = "text" name="t1" id = "t1">

document.getElementById() requires that the element has an id.

With the alteration above the code works.


It's a 32-team tournament and all but one or two are in the Fifa top-20 rankings. - Commentator Sky Sports News

WolfShade
06-22-2012, 07:20 PM
<input name="t1" type="t1" />

The object has to have an ID, and the type needs to be TEXT.

<input name="t1" id="t1" type="text" />

felgall
06-22-2012, 08:48 PM
If you are trying to set up a combo box then it is far easier to do it with a text input field and a list and not use a select at all in HTML4 (you still need to use JavaScript to connect the two).

You can use a <datalist> with your text input field to fully define a combobox in HTML5.

jmrker
06-22-2012, 11:46 PM
This will not do what you expect it to do ...


...
if (value = 'Value1') {
...


Should be:
if (value == 'Value1') {

felgall
06-22-2012, 11:51 PM
This will not do what you expect it to do ...


...
if (value = 'Value1') {
...


Should be:
if (value == 'Value1') {

A safer way to code comparisons with static strings is to put the string first - that way if you accidentally leave out an = you get a syntax error instead of the code doing the wrong thing.

Also using == is considered to be poor coding in JavaScript - you should use === instead.

if ('Value1' === value)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum