Change Hidden Field to Text Field based on select list

[Total: 0    Average: 0/5]

This script is to answer a question posted on a Javascript forum.

Head Code:

<script language="JavaScript">

function SwitchField(selectvalue)
{
if (selectvalue=='inputID')
{
if (document.all)
{
document.all["showfield"].style.visibility = "visible";
}
else
{
eval("document.layers['showfield'].visibility = 'show';");
}
}
else if (selectvalue=='noID')
{
if (document.all)
{
document.all["showfield"].style.visibility = "hidden";
}
else
{
eval("document.layers['showfield'].visibility = 'hide';");
}
}
}

// you should test this function
function form_submit()
{
if (document.all)
{
if (document.all["showfield"].style.visibility == "visible")
{
document.testhide.hidefield.value=document.show_field.InputID.value;
}
}
else
{
if (eval("document.layers['showfield'].visibility")=="show")
{
document.testhide.hidefield.value=document.layers[0].document.show_field.InputID.value;
}
}

document.testhide.submit();
}


</script>

Body Code:

<script language="JavaScript">


var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var IsIEPlus = false;
var IsNSPlus = false;

var hpStr;

if ((bName == "Netscape") && (bVer >= 3))
{
    IsNSPlus = true;
}
else if ((bName == "Microsoft Internet Explorer") && (bVer >=4))
{
    IsIEPlus = true;
}

if (IsIEPlus)
{
document.write('<span id="showfield" style="visibility:hidden; position:absolute;top:40; left:10">');
}
else if (IsNSPlus)
{
document.write('<span id="showfield" style="visibility:hide; position:absolute;top:40; left:10">');
}


</script>
<form name="show_field">
Input ID: <input type="text" name="InputID">
</form>
</span>

<form name="testhide" action="./test.html">
Select Field: <select name="test" size=1 onChange="SwitchField(document.testhide.test.options[document.testhide.test.selectedIndex].value)">
<option value="noID">Hidden ID Field</option>
<option value="inputID">Input ID Field</option>
</select>

<input type="hidden" name="hidefield">
<br><br><br>
<input type="button" name="txtbutton" value="Submit" onClick="form_submit()">
</form>

Times Viewed: 2

Leave a Reply

Your email address will not be published. Required fields are marked *