|
-
Feb 16th, 2005, 09:16 PM
#1
Thread Starter
Junior Member
newbee's simple question
Hi Everyone,
I'm a newbee and need your help on this.
I have this line of code in the page:
Protected WithEvents hdnChecklist As System.Web.UI.WebControls.TextBox
hdnChecklist.Text = "Test"
Button_Submit.Attributes.Add("OnClick", "onSubmit()")
It call the JavaScript func:
<script language="javascript"
function onSubmit(){
if document.Form1.hdnChecklist.text == "Test" {
alert(document.Form1.hdnChecklist.text);
document.Form1.submit();
}
}
</script>
For some weired reason the value of my textbox is not getting past or the function can't see it. What am I missing here??? It's such a simple test and it's driving me crazy why it doesn't work...
Thanks much!!
Gina
-
Feb 17th, 2005, 06:14 AM
#2
Re: newbee's simple question
If you view the page in the browser, (look at it's source), you'll see that the textbox most likely has a different ID. You need to plug in that ID into your javascript code.
-
Feb 17th, 2005, 06:48 AM
#3
New Member
Re: newbee's simple question
I think in JS, you reference the contents of textbox (and other form items) with hdnChecklist.Value, not hdnChecklist.Text (which is the way VB does it).
-
Feb 17th, 2005, 12:40 PM
#4
Thread Starter
Junior Member
Re: newbee's simple question
Hi Sandpaper and scottst!
You both were right. Once I fixed the id and text to value my alert worked displaying the: "Test".
<script language="javascript"
function onSubmit(){
alert(document.Form1.hdnChecklist.value);
document.Form1.submit();
}
</script>
But when I put a condition in - the code doesn't work:
<script language="javascript"
function onSubmit(){
if document.Form1.hdnChecklist.value == "Test" {
alert(document.Form1.hdnChecklist.value);
document.Form1.submit();
}
}
</script>
Why???
Thanks a lot!
Gina
-
Feb 17th, 2005, 12:51 PM
#5
New Member
Re: newbee's simple question
You also need brackets around the condition!
if (document.Form1.hdnChecklist.value == "Test") {
-
Feb 17th, 2005, 12:56 PM
#6
Thread Starter
Junior Member
Re: newbee's simple question
-
Feb 17th, 2005, 01:21 PM
#7
Thread Starter
Junior Member
Re: newbee's simple question
Sorry... I see now that I missed the brackets! I can't grasp when you need to insert paranthesis ( and {} in JavaScript. It seems that I've always miss them and there is no way to debug to see why the code doesn't work. Is there a simple rule for dummies ??
Gina
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|