I'm inexperienced enough with Javascript that I couldn't tell if any of the other posts addressed my issue or not. Sorry if this is a repeat and feel free to point me to the post, if there is one.
I have an ASP.net VB page with a checkbox for reject and a textbox for Quantity Rejected. I'm trying to get a javascript prompt, asking for the reject qty, to open when the checkbox is checked. The user will enter a quantity in the prompt and the quantity rejected will fill with that quantity. Once the text in the quantity rejected textbox changes that will trigger some other stuff from the codebehind. If it makes a difference my checkboxes and textboxes are asp controls rather than html input controls.
I originally had the script working, sort of, from the script on the markup page with the script below. I say sort of because it was firing whether the checkbox was checked or unchecked.
I've now moved the script to the checkbox's OnCheckedChanged event in the codebehind.Code:var qrcheck = document.getElementById('bolRej1'); if (qrcheck.checked) { function rQty() { var rq = prompt('Enter Reject Qty', ''); document.getElementById('txtQtyRej').value = rq; } }
With the codebehind method the prompt never opens. I can include a break point and see that it is running through the stringbuilder and apparently running the script but the prompt isn't opening and I just see //]]> at the bottom of my page and see the code below in view source.Code:Protected Sub bolRej1_CheckedChanged(sender As Object, e As EventArgs) Handles bolRej1.CheckedChanged If bolRej1.Checked = True Then Dim sb As New System.Text.StringBuilder() sb.Append("<script Type ='javascript'>") sb.Append("function rQty() {") sb.Append("var rq = prompt('Enter Reject Qty', '');") sb.Append("document.getElementById('txtQtyRej').value = rq;") sb.Append("}</script>") ScriptManager.RegisterStartupScript(Page, Page.GetType(), "rQtyFunction", sb.ToString(), True) End If End Sub
I'm not sure what I'm missing. Am I completely off track. Any and all help would be greatly appreciated!Code:<script type="text/javascript"> //<![CDATA[ <script Type ='javascript'>function rQty() {var rq = prompt('Enter Reject Qty', '');document.getElementById('txtQtyRej').value = rq;}}</script>//]]> </script>




Reply With Quote
