PDA

Click to See Complete Forum and Search --> : newbee's simple question


Ginab
Feb 16th, 2005, 08:16 PM
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

mendhak
Feb 17th, 2005, 05:14 AM
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.

scottst
Feb 17th, 2005, 05:48 AM
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).

Ginab
Feb 17th, 2005, 11:40 AM
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

scottst
Feb 17th, 2005, 11:51 AM
You also need brackets around the condition!

if (document.Form1.hdnChecklist.value == "Test") {

Ginab
Feb 17th, 2005, 11:56 AM
I do have brackets...

Ginab
Feb 17th, 2005, 12:21 PM
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