Results 1 to 7 of 7

Thread: newbee's simple question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    31

    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

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  3. #3
    New Member
    Join Date
    Feb 2005
    Posts
    3

    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).

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    31

    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

  5. #5
    New Member
    Join Date
    Feb 2005
    Posts
    3

    Re: newbee's simple question

    You also need brackets around the condition!

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

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    31

    Re: newbee's simple question

    I do have brackets...

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    31

    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
  •  



Click Here to Expand Forum to Full Width