...

View Full Version : Moving value from 1 input textbox to another



schenn
12-26-2010, 08:12 PM
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<meta http-equiv='Content-Script-Type' content='text/javascript'>
<script type = 'text/javascript'>
function unselectall(form)
{
var i=0;
for(i=0;i<=15;i++)
{
tdname = 'invbox'+i;
if (document.getElementById && document.getElementById(tdname).style)
{
document.getElementById(tdname).style.borderColor = '#000000';
form.selected.value = 0;
}
else
{
i=20;
}
}
}

function selectthis(form, pos)
{
unselectall(form);
var tdname = 'inventory';
document.getElementById(tdname).style.borderColor = '#ffff00';
form.selected.value = form.position1.value;
}

</script>

</head>
<body>
<form id='inventorytable' method='post' action='addflowerlight.php'>
<table id='inventory' border=1>
<tr>
<td id = 'invbox1' ><img src = 'images/Lights/6inv.jpg' onclick="selectthis('inventorytable', 1);"><input type = 'text' id = 'position1' value='6'></td></tr></table>
<input type ='text' id='selected'>
<input type ='submit' value='Equip Light'>
</form>
</body>
</html>


What am I doing wrong? The onclick wont trigger.

Krupski
12-26-2010, 10:39 PM
What am I doing wrong? The onclick wont trigger.

Change all your single quotes to double quotes in HTML and use single quotes in Javascript.

Example:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type = "text/javascript">
function unselectall(form)
{
var i=0;
for(i=0;i<=15;i++)
{
tdname = 'invbox'+i;
if (document.getElementById && document.getElementById(tdname).style)
{
document.getElementById(tdname).style.borderColor = '#000000';
form.selected.value = 0;
}
else
{
i=20;
}
}
}

function selectthis(form, pos)
{
unselectall(form);
var tdname = 'inventory';
document.getElementById(tdname).style.borderColor = '#ffff00';
form.selected.value = form.position1.value;
}

</script>

</head>

<body>
<form id="inventorytable" method="post" action="addflowerlight.php">
<table id="inventory" border=1>
<tr>
<td id ="invbox1" >
<img src ="images/Lights/6inv.jpg" onclick="selectthis('inventorytable', 1);">
<input type ="text" id ="position1" value="6">
</td>
</tr>
</table>
<input type ="text" id="selected">
<input type ="submit" value="Equip Light">
</form>
</body>
</html>

schenn
12-26-2010, 11:15 PM
Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum