PDA

View Full Version : Form Field Value



mw2005
Mar 11th, 2007, 05:23 PM
Whenever i run this script the value does not change,

What is wrong?



<script>
function insertit()
{
var nameval = document.formval.name.value;
if(nameval == null)
{
nameval = "Unknown";
}
}
</script>


<form name="formval">
<input type="text" name="name" /><a href="javascript:insertit()"> -></a>
</form>

Mr J
Mar 11th, 2007, 05:32 PM
Change

nameval = "Unknown";

to

document.formval.name.value = "Unknown";

mw2005
Mar 11th, 2007, 06:15 PM
Thanks for that but it is still not working

Mr J
Mar 11th, 2007, 11:20 PM
Sorry, I forgot to say the following as well

change

if(nameval == null)

to

if(nameval == "")



<script type="text/javascript">
function insertit(){
var nameval = document.formval.name.value;

if(nameval == ""){
document.formval.name.value = "Unknown";
}

}
</script>

<form name="formval">
<input type="text" name="name" /><a href="javascript:insertit()"> -></a>
</form>