anyone good with javascript?

Discussion in 'ASP .Net' started by =?Utf-8?B?UGF1bA==?=, Jul 7, 2005.

  1. Hi I have 3 drop down list boxes on a webform with a submit button. When the
    submit button is selected if any of the dropdown listbox selected index = 0 I
    want to popup a message box and not allow the submit to work. Anyhow
    thinking this may require javascript.
    thanks.
    --
    Paul G
    Software engineer.
     
    =?Utf-8?B?UGF1bA==?=, Jul 7, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?UGF1bA==?=

    Phillip Ian Guest

    Assuming your lists are DropDownList1, 2 and 3, and your button is
    btnOk...

    In page_load:

    btnOk.Attributes.Add("onClick", "javascript:return validateOk()")
    Dim s As String = ""
    s &= vbCrLf & "<script language='javascript'><!--" & vbCrLf
    s &= vbTab & "function validateOk() {" & vbCrLf
    s &= vbTab & vbTab & "if (document.Form1." & DropDownList1.ClientID
    & ".selectedIndex == 0) { " & vbCrLf
    s &= vbTab & vbTab & vbTab & "alert('Choose from the first
    dropdown!');" & vbCrLf
    s &= vbTab & vbTab & vbTab & "return false;" & vbCrLf
    s &= vbTab & vbTab & "}" & vbCrLf
    s &= vbTab & vbTab & "if (document.Form1." & DropDownList2.ClientID
    & ".selectedIndex == 0) { " & vbCrLf
    s &= vbTab & vbTab & vbTab & "alert('Choose from the second
    dropdown!');" & vbCrLf
    s &= vbTab & vbTab & vbTab & "return false;" & vbCrLf
    s &= vbTab & vbTab & "}" & vbCrLf
    s &= vbTab & vbTab & "if (document.Form1." & DropDownList3.ClientID
    & ".selectedIndex == 0) { " & vbCrLf
    s &= vbTab & vbTab & vbTab & "alert('Choose from the third
    dropdown!');" & vbCrLf
    s &= vbTab & vbTab & vbTab & "return false;" & vbCrLf
    s &= vbTab & vbTab & "}" & vbCrLf
    s &= vbTab & vbTab & "return true;" & vbCrLf
    s &= vbTab & "}" & vbCrLf
    s &= "--></script>" & vbCrLf
    Page.RegisterClientScriptBlock("OkButtonVal", s)

    You can, of course, omit a lot of the vbTab and vbCrLf stuff...I just
    throw it in for readability when debugging.
     
    Phillip Ian, Jul 7, 2005
    #2
    1. Advertising

  3. =?Utf-8?B?UGF1bA==?=

    jasonkester Guest

    First of all, Yikes!

    What's stopping you from putting that Script block in the HTML, where
    it belongs? In fact, that whole thing should be client side:

    <input type="submit" onclick="return validateOk();" runat=server/>

    <script>
    // decode all that script above and put it here.
    </script>

    Good luck!

    Jason Kester
    Expat Software Consulting Services
    http://www.expatsoftware.com/
     
    jasonkester, Jul 7, 2005
    #3
  4. ok will give it a try thanks.
    --
    Paul G
    Software engineer.


    "Phillip Ian" wrote:

    > Assuming your lists are DropDownList1, 2 and 3, and your button is
    > btnOk...
    >
    > In page_load:
    >
    > btnOk.Attributes.Add("onClick", "javascript:return validateOk()")
    > Dim s As String = ""
    > s &= vbCrLf & "<script language='javascript'><!--" & vbCrLf
    > s &= vbTab & "function validateOk() {" & vbCrLf
    > s &= vbTab & vbTab & "if (document.Form1." & DropDownList1.ClientID
    > & ".selectedIndex == 0) { " & vbCrLf
    > s &= vbTab & vbTab & vbTab & "alert('Choose from the first
    > dropdown!');" & vbCrLf
    > s &= vbTab & vbTab & vbTab & "return false;" & vbCrLf
    > s &= vbTab & vbTab & "}" & vbCrLf
    > s &= vbTab & vbTab & "if (document.Form1." & DropDownList2.ClientID
    > & ".selectedIndex == 0) { " & vbCrLf
    > s &= vbTab & vbTab & vbTab & "alert('Choose from the second
    > dropdown!');" & vbCrLf
    > s &= vbTab & vbTab & vbTab & "return false;" & vbCrLf
    > s &= vbTab & vbTab & "}" & vbCrLf
    > s &= vbTab & vbTab & "if (document.Form1." & DropDownList3.ClientID
    > & ".selectedIndex == 0) { " & vbCrLf
    > s &= vbTab & vbTab & vbTab & "alert('Choose from the third
    > dropdown!');" & vbCrLf
    > s &= vbTab & vbTab & vbTab & "return false;" & vbCrLf
    > s &= vbTab & vbTab & "}" & vbCrLf
    > s &= vbTab & vbTab & "return true;" & vbCrLf
    > s &= vbTab & "}" & vbCrLf
    > s &= "--></script>" & vbCrLf
    > Page.RegisterClientScriptBlock("OkButtonVal", s)
    >
    > You can, of course, omit a lot of the vbTab and vbCrLf stuff...I just
    > throw it in for readability when debugging.
    >
    >
     
    =?Utf-8?B?UGF1bA==?=, Jul 7, 2005
    #4
  5. yep thinking it should all be done on the client side (html)
    --
    Paul G
    Software engineer.


    "jasonkester" wrote:

    > First of all, Yikes!
    >
    > What's stopping you from putting that Script block in the HTML, where
    > it belongs? In fact, that whole thing should be client side:
    >
    > <input type="submit" onclick="return validateOk();" runat=server/>
    >
    > <script>
    > // decode all that script above and put it here.
    > </script>
    >
    > Good luck!
    >
    > Jason Kester
    > Expat Software Consulting Services
    > http://www.expatsoftware.com/
    >
    >
     
    =?Utf-8?B?UGF1bA==?=, Jul 7, 2005
    #5
  6. =?Utf-8?B?UGF1bA==?=

    Mark Rae Guest

    "Paul" <> wrote in message
    news:...

    > yep thinking it should all be done on the client side (html)


    Definitely.
     
    Mark Rae, Jul 8, 2005
    #6
  7. =?Utf-8?B?UGF1bA==?=

    Phillip Ian Guest

    My only excuse is that I work with lots of user controls...thus I need
    to use .ClientID rather than the actual name of the component.

    If it's all on the page, I guess no reason. :)

    -Phil
     
    Phillip Ian, Jul 8, 2005
    #7
  8. =?Utf-8?B?UGF1bA==?=

    jasonkester Guest

    Sounds reasonable enough. Though I'd probably still try to only spit
    out as much code from the server as necessary:

    Dim handleScript As String = String.Format("var boxHandle = {0};",
    box.ClientID);
    Page.RegisterClientScriptBlock­(handleScript) ;

    <script>
    function box_IndexChanged
    {
    var box = document.getElementByID(boxHandle);
    ...
    }
    </script>


    Jason Kester
    Expat Software Consulting Services
    http://www.expatsoftware.com/
     
    jasonkester, Jul 9, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shapper
    Replies:
    5
    Views:
    355
    Kevin Spencer
    Apr 26, 2005
  2. Mephistopheles

    Does anyone know a good javascript forum?

    Mephistopheles, Jun 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    391
  3. JDS

    Anyone?? Anyone at all??

    JDS, Sep 26, 2005, in forum: HTML
    Replies:
    2
    Views:
    395
    Montgomery BOO...URNS
    Sep 29, 2005
  4. Steve Williams

    Anyone? Anyone?

    Steve Williams, Sep 16, 2003, in forum: Python
    Replies:
    0
    Views:
    394
    Steve Williams
    Sep 16, 2003
  5. Paul

    anyone good with javascript!

    Paul, Jun 24, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    327
Loading...

Share This Page