JSFiddle - React, Tailwind, and code Playground
by NickU
HTML
<input id="radiocharm-855264" name="sectype" type="radio" value="bond">
<input id="radiocharm-934406" name="sectype" type="radio" value="option">
<input id="radiocharm-917929" name="sectype" type="radio" value="other">
<select class="infield" name="sectype2" size="1" id="sectype2" >
<option value="stock" style="font-weight:bold;">Stock</option><option value="bond" selected="" style="font-weight:bold;">Bond</option><option value="option" style="COLOR: #555;">Options</option><option value="mf" style="font-weight:bold;">Mutual Fund</option><option value="uit" style="font-weight:bold;">UIT</option><option value="etn" style="font-weight:bold;">ETN</option><option value="etf" style="font-weight:bold;">ETF</option><option value="partn" style="font-weight:bold;">Partnership</option><option value="trust" style="font-weight:bold;">Trust</option><option value="other" style="font-weight:bold;">Other</option><option value="future" style="COLOR: #555;">Future</option><option value="cash" style="COLOR: #555;">Cash</option></select>
Out1: <span id=out1></span>
Out2 <span id=out2></span>
JavaScript
var cur_sectype = _GetVal('[name=sectype]');
if ($.trim(cur_sectype) == '')
{
var v = $('[name=sectype]')[1].value;
console.log(v);
_SetVal('[name=sectype]',v).change();
}
console.log(cur_sectype);
_SetVal('[name=sectype2]','option').change();
function _GetVal($id)
{
var $this = $($id);
if ($this && $this.length > 0)
{
var el = $this[0];
switch (el.type)
{
case 'radio':
for (i = 0; i < $this.length; i++) if ($this[i].checked)
return $this[i].value;
return '';
case 'checkbox':
var result = '';
for (i = 0; i < $this.length; i++)
{
if ($this[i].checked)
{
if (result != '')
result = result + ',';
result = result + result[i].value;
}
}
return result;
case 'select-multiple':
var result = '';
for (i = 0; i < $this.length; i++)
{
if ($this[i].options[i].selected)
{
if (result != '')
result = result + ',';
result = result + $this[i].options[i].value;
}
}
return result;
default:
var v = $this.val();
if (typeof v !== 'undefined' && el !== null)
return $.trim(v);
}
return el.value;
}
return '';
}
function _SetVal($id, nVal)
{
var $this = $($id);
if ($this && $this.length > 0)
{
var el = $this[0];
switch (el.type)
{
case 'checkbox':
case 'radio':
for (i = 0; i < $this.length;...