Resna
asked on
Populate hidden fields with JavaScript problem
Hi Guys,
First off I know nothing (about JavaScript)
What I would like to do is have a certain amount of clickable links, that once clicked a hidden form field within a HTML table cell is updated to the value of ' 1 '.
So lets say there is 1 table row with 4 columns, each of these columns has a link in (1,2,3,4) and a hidden field. Once a link is clicked the value of the hidden field in the same column as the link gets updated to ' 1 '
Then if another link is clicked the same happens.
So when the ' Submit ' button is pressed there is a value of ' 1 ' set to all of the hidden fields that the corresponding link was clicked.
I've attached some code, which may make more sense. I've tried to use some JavaScript but it only seems to add 1 value to only 1 hidden field.
Many thanks
Resna
First off I know nothing (about JavaScript)
What I would like to do is have a certain amount of clickable links, that once clicked a hidden form field within a HTML table cell is updated to the value of ' 1 '.
So lets say there is 1 table row with 4 columns, each of these columns has a link in (1,2,3,4) and a hidden field. Once a link is clicked the value of the hidden field in the same column as the link gets updated to ' 1 '
Then if another link is clicked the same happens.
So when the ' Submit ' button is pressed there is a value of ' 1 ' set to all of the hidden fields that the corresponding link was clicked.
I've attached some code, which may make more sense. I've tried to use some JavaScript but it only seems to add 1 value to only 1 hidden field.
Many thanks
Resna
<?php
foreach($_POST as $key => $value){
echo $value;
}
?>
<html>
<head>
<script type="text/javascript">
function add(){
i = document.getElementById('link').value;
eval("document.form1." + i + ".value='1'")
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="Untitled-3.php">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="hidden" name="s1" />
<a href="#" id="link" value="s1" onclick="add()">3</a></td>
<td><input type="hidden" name="s2" />
<a href="#" id="link" value="s2" onclick="add()">4</a></td>
<td><input type="hidden" name="s3" />
<a href="#" id="link" value="s3" onclick="add()">5</a></td>
<td><input type="hidden" name="s4" />
<a href="#" id="link" value="s4" onclick="add()">6</a></td>
</tr>
</table>
<input type="submit" name="button" id="button" value="Submit" />
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works perfectly, and I understand where I went wrong!
Many thanks
Resna