saragose
asked on
Issues with Hidden fields (HTML/Javascript)
Hi there,
I'm writing some code in ASP to generate HTML.
Part of what I'm trying to do requires me to have a hidden field containing the PK of the line of the combobox.
I've tried setting an onchange event, and setting the hidden field directly, but it didn't work. Neither did writing a javascript routine to do it.
Looking at it further, when I ran the code in the microsoft developper, it saw all the other tags, except the hidden one.
I'm not sure how to make the change, so any help would be great. I'm attaching the html created by the asp.
Thanks
Eric
I'm writing some code in ASP to generate HTML.
Part of what I'm trying to do requires me to have a hidden field containing the PK of the line of the combobox.
I've tried setting an onchange event, and setting the hidden field directly, but it didn't work. Neither did writing a javascript routine to do it.
Looking at it further, when I ran the code in the microsoft developper, it saw all the other tags, except the hidden one.
I'm not sure how to make the change, so any help would be great. I'm attaching the html created by the asp.
Thanks
Eric
<script type='text/javascript'>
function change()
{
document.getElementById('txtID').value='5';
return;
}
</script>
<html>
<head>
<title>WSPCHS Congress - Please Confirm User</title>
</head>
<BODY>
<p>More than one user appears with that username.</p>
<p>Please confirm which one is you:</p>
<form name="frmName" method="post" action="">
<p>
<input type="hidden" name="txtID">
<select name="cmbUserlist" onchange="change()">
<OPTION VALUE=2>Dr.
Bruce
Wayne, Gotham, New york, United States
<OPTION VALUE=999>Mr.
Bruce
Wayne, earth2, earth2, United States
</select>
</p>
<p>
<input type="submit" name="Submit" value="Confirm">
<input type="submit" name="Submit2" value="New User">
<input type="submit" name="Submit3" value="Back">
</p>
</form>
<p> </p>
</BODY>
</html>
ASKER
Hey there,
I've tried a few variations, but with no success.
Ideally I would like to be able to have my hidden field be something like:
<input type="hidden" name="txtID" value='Test'>
and my routine say something like:
<script type='text/javascript'>
function change()
{
document.frmName.txtID.val ue='5';
return;
}
</script>
Unfortunately that doesn't seem to work, and I pull up the values assinged to the hidden fields using alerts. I also tried using the ID and getElementByID, but I can't seem to set the value of the hidden field that way.
Thanks
Eric
I've tried a few variations, but with no success.
Ideally I would like to be able to have my hidden field be something like:
<input type="hidden" name="txtID" value='Test'>
and my routine say something like:
<script type='text/javascript'>
function change()
{
document.frmName.txtID.val
return;
}
</script>
Unfortunately that doesn't seem to work, and I pull up the values assinged to the hidden fields using alerts. I also tried using the ID and getElementByID, but I can't seem to set the value of the hidden field that way.
Thanks
Eric
Maybe I'm not understanding the problem, because the following code works fine for me at seeing the value of the hidden field.
<script type='text/javascript'>
function change()
{
document.frmName.txtID.value='5';
alert(document.getElementById('txtID').value);
}
</script>
<html>
<head>
<title>WSPCHS Congress - Please Confirm User</title>
</head>
<BODY>
<p>More than one user appears with that username.</p>
<p>Please confirm which one is you:</p>
<form name="frmName" method="post" action="">
<p>
<input type="hidden" name="txtID" id="txtID">
<select name="cmbUserlist" onchange="change()">
<OPTION VALUE=2>Dr.
Bruce
Wayne, Gotham, New york, United States
<OPTION VALUE=999>Mr.
Bruce
Wayne, earth2, earth2, United States
</select>
</p>
<p>
<input type="submit" name="Submit" value="Confirm">
<input type="submit" name="Submit2" value="New User">
<input type="submit" name="Submit3" value="Back">
</p>
</form>
<p> </p>
</BODY>
</html>
ASKER
Hey there,
The code that you gave me gives me the correct pop-up.
Unfortunately, if you look at the source code, it doesn't seem to be changed.
Is that normal? And will the next page be able to read this hidden box correctly using the request object?
Thanks
Eric
The code that you gave me gives me the correct pop-up.
Unfortunately, if you look at the source code, it doesn't seem to be changed.
Is that normal? And will the next page be able to read this hidden box correctly using the request object?
Thanks
Eric
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<input type="hidden" name="txtID"> has no id, so getElementById won't work
<input type="hidden" name="txtID" id="txtID"> now you can use getElementById