Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do i use Javascript code in Scriptlets

Status
Not open for further replies.

kuha

Technical User
Oct 23, 2001
14
US
Hi friends,
i am trying to get the value of check box , i tried like,
request.getParameter("checkbox");
but iam getting null, so i want to try some thing like this
String variable = Javascript:'document.checkbox.value;'
Is it correct, if not please suggest me how to do this.
Thanks in advance for all the help.
Harish
 
Well, checkboxes don't really have a value unless you assign a value to them. Otherwise on the client side, the value will always be on whether it is checked or not. If you do assign a value to the checkbox, then client side script will return that value.

If you're trying to check the status of a checkbox on the client to see whether or not it's checked, the syntax is a little different. Since I don't know what you're really trying to do, here's a sample page with client side script. Press the button and it will display both the value and the status. Do that a few times with the checkbox checked and unchecked, then remove the value parameter from the checkbox and do it again. I think you'll start to see the differences.
Code:
<html>
<head>
<script Language=&quot;JavaScript&quot;>
<!--
function getVal() {
  window.alert(&quot;Value = &quot; + document.myForm.check1.value)
  window.alert(&quot;Status = &quot; + document.myForm.check1.checked)
}
//-->
</script>
</head>
<body>
<form name=&quot;myForm&quot;>
<input type=&quot;checkbox&quot; value=&quot;myCheck1&quot; name=&quot;check1&quot;>Check #1</input><br>
<input type=&quot;button&quot; value=&quot;Do It&quot; onClick=&quot;getVal();&quot;>
</form>
</body>
</html>
ToddWW
 
Hi ToddWW,
Yes i am trying to see whether checkbox is checked or not, and i want value to be 1 if checkbox is checked and value must be 0 if checkbox is unchecked.
More over i want this value to be accessed in Scriptlet, like
request.getParameter(&quot;checkbox&quot;).
i understood u'r code and thanks for it, but if u know how can i do the above mentioned it will help me a lot.
Thanks ToddWW for all the help.
Harish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top