tomfulton
asked on
Validate a checkbox and corresponding text box.
I have a form with multiple checkboxes. the last checkbox has a corresponding textbox for a write in value.
I would like to make sure that the textbox can only be filled in if the corresponding checkbox is checked and if that same checkbox is then unchecked then the textbox is cleared out.
I would like to make sure that the textbox can only be filled in if the corresponding checkbox is checked and if that same checkbox is then unchecked then the textbox is cleared out.
<form name="userlist" method="post">
<input name="user1" type="checkbox">User1
<input name="user2" type="checkbox">User2
<input name="1writein" type="checkbox">><input type="text" name="1wi" value="">
<input type="submit" name="submit">
</form>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
yeah, that's what I was attempting, but I have a typo
<%
dim frmField : frmField = request.querystring("1writein")
dim frmField2 : frmField2 = request.querystring("1wi")
if not isnull(frmField) or not isempty(frmField) or not(frmField = "") then
if not isnull(frmField2) or not isempty(frmField2) or not(frmField2 = "") then
'process the form here
else
'don't process it, throw a message at the user if you need to, etc
end if
end if
%>
ASKER
Is this code from the last submission:
<%
dim frmField : frmField = request.querystring("1writ ein")
dim frmField2 : frmField2 = request.querystring("1wi")
if not isnull(frmField) or not isempty(frmField) or not(frmField = "") then
if not isnull(frmField2) or not isempty(frmField2) or not(frmField2 = "") then
'process the form here
else
'don't process it, throw a message at the user if you need to, etc
end if
end if
%>
something I will put on the same page as the code for the form? I wanted to do it on the client side if I could so I could catch the blank textbox and checked checkbox before it is submitted.
Thank you
<%
dim frmField : frmField = request.querystring("1writ
dim frmField2 : frmField2 = request.querystring("1wi")
if not isnull(frmField) or not isempty(frmField) or not(frmField = "") then
if not isnull(frmField2) or not isempty(frmField2) or not(frmField2 = "") then
'process the form here
else
'don't process it, throw a message at the user if you need to, etc
end if
end if
%>
something I will put on the same page as the code for the form? I wanted to do it on the client side if I could so I could catch the blank textbox and checked checkbox before it is submitted.
Thank you
The first comment does exactly that. It is on the client side, and demonstrates how to check not only the value of the radiobutton, but also clear the text field should the last radtiobutton be unchecked.
https://www.experts-exchange.com/questions/22989078/Validate-a-checkbox-and-corresponding-text-box.html#20369410
https://www.experts-exchange.com/questions/22989078/Validate-a-checkbox-and-corresponding-text-box.html#20369410
You probably want to do it both on client and on server side. Client side only works if people have javascript turned on, and no greasemonkey script running to overrule your script.
And yes, the first comment posted does the client side thing. Although it's a bit bit longer then what I suggested.
And yes, the first comment posted does the client side thing. Although it's a bit bit longer then what I suggested.
sybe's correct (as previously stated...)
You would put that code on whatever page that is processing the form. If your <form action is another page, it would go on that....unless you are doing a post-back in which case you would put it on the page the form is on...
You would put that code on whatever page that is processing the form. If your <form action is another page, it would go on that....unless you are doing a post-back in which case you would put it on the page the form is on...
ASKER
HonorGod:
I put that code in an asp page by itself and my javascript is on but no alert came up and the textbox does not clear if the corresponding checkbox is unchecked.
so I looked into the server side possibility and
sybe:
Do I put your code in the same page as my form itself?
I put that code in an asp page by itself and my javascript is on but no alert came up and the textbox does not clear if the corresponding checkbox is unchecked.
so I looked into the server side possibility and
sybe:
Do I put your code in the same page as my form itself?
ASKER
I don't know if I worded the problem different than what I need but in a set of checkboxes a user can select more than one choice but if the user wants the write-in then I want to verify that Both the write-in textbox and its corresponding checkbox is checked.
Thank you for looking at this
Thank you for looking at this
Strange. I'm not familiar enough with asp so as to be able to understand why this would be the case. If you add an alert to the function to prove that it is getting called, do you see it's output?
For example:
For example:
function checkIt( obj, id ) {
alert( 'checkIt()' );
var field = document.getElementById( id );
...
what I posted for you will do the server side you need
ASKER
Since the client side didn't work at first, I went with the server side solutions.
Thanks for the assistance.
Thanks for the assistance.
Open in new window