html tags and python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hansan

    #1

    html tags and python

    Hi all

    I am making something for my webpage

    Where the user can choose a month: I have made that with a dropdown box.

    <select>
    <option name = "1" value="1">Janua ry
    <option name = "2" value="2">Febru ary
    <option name = "3" value="3">March
    <option name = "4" value="4">April
    <option name = "5" value="5">May
    <option name = "6" value="6">June
    <option name = "7" value="7">July
    <option name = "8" value="8">Augus t
    <option name = "9" value="9">Septe mber
    <option name = "10" value="10">Octo ber
    <option name = "11" value="11">Nove mber
    <option name = "12" value="12">Dece mber
    </select>

    The thing is:
    I also want the user to choose a date
    I will make this with another dropdownbox.
    But if the first month is selected, then there should be 31 days in the days
    dropdownbox, if the second month is selected there should be 28 days in the
    dropdownbow.

    I Know a little of python programming, but not to much, I have a feeling of
    that I should use a cgi, can any explain me what I have to do :? Or give me
    a link to a site where I can copy the code for it

    All help will be greatly appreciated.

    Thanks for your time



  • Kane

    #2
    Re: html tags and python

    If I understand what you are asking then Python & CGI are a poor
    solution. It would be easy to have one page ask for the month, click
    submit, then have a second page ask for the exact date. Easy; but
    terrible design.

    You want to have one page with a dropdown of months. When you select a
    month, you want to dynamicly alter a dropdown of dates without
    refreshing the page.

    For this task you'll want to pull JavaScript out of your toolbox. This
    is a fairly common "problem" and googling for examples/samples should
    be quick-n-easy.

    Comment

    • Hansan

      #3
      Re: html tags and python

      Thanks.

      Do you know what I should google after, which key words ?

      regards...


      "Kane" <jason.w.kane@g mail.com> wrote in message
      news:1111794379 .636347.313670@ g14g2000cwa.goo glegroups.com.. .[color=blue]
      > If I understand what you are asking then Python & CGI are a poor
      > solution. It would be easy to have one page ask for the month, click
      > submit, then have a second page ask for the exact date. Easy; but
      > terrible design.
      >
      > You want to have one page with a dropdown of months. When you select a
      > month, you want to dynamicly alter a dropdown of dates without
      > refreshing the page.
      >
      > For this task you'll want to pull JavaScript out of your toolbox. This
      > is a fairly common "problem" and googling for examples/samples should
      > be quick-n-easy.
      >[/color]


      Comment

      • Dan Bishop

        #4
        Re: html tags and python

        Kane wrote:[color=blue]
        > If I understand what you are asking then Python & CGI are a poor
        > solution. It would be easy to have one page ask for the month, click
        > submit, then have a second page ask for the exact date. Easy; but
        > terrible design.[/color]

        An improvement is to just have the dropdown listbox go from 1 to 31,
        and if the user enters an invalid date, give them an error message and
        ask them to re-enter the date.

        Comment

        • Tim Roberts

          #5
          Re: html tags and python

          "Hansan" <none> wrote:[color=blue]
          >
          >Hi all
          >
          >I am making something for my webpage
          >
          >Where the user can choose a month: I have made that with a dropdown box.
          >
          > <select>
          > <option name = "1" value="1">Janua ry
          > <option name = "2" value="2">Febru ary
          > <option name = "3" value="3">March
          > <option name = "4" value="4">April
          > <option name = "5" value="5">May
          > <option name = "6" value="6">June
          > <option name = "7" value="7">July
          > <option name = "8" value="8">Augus t
          > <option name = "9" value="9">Septe mber
          > <option name = "10" value="10">Octo ber
          > <option name = "11" value="11">Nove mber
          > <option name = "12" value="12">Dece mber
          > </select>
          >
          >The thing is:
          >I also want the user to choose a date
          >I will make this with another dropdownbox.
          >But if the first month is selected, then there should be 31 days in the days
          >dropdownbox, if the second month is selected there should be 28 days in the
          >dropdownbow.[/color]

          What if the year is 2004? Then I assume you want 29 days in the listbox.
          And that, of course, means they have to choose the year first.

          This can be done, but it's a lot of trouble. You might consider allowing 1
          to 31 and validating the numbers in your "onSubmit" handler.

          Or, even better, skip the listbox and just let me type the damn numbers
          myself. I hate being forced to fall back to my mouse to type in a date,
          when I can type "3 tab 25 tab 2005" much quicker. To do that with your
          code, I have to type "m tab 2 2 2 2 2 2 tab 2005".

          As an alternative, there are Javascript-based mini-calendars you can
          download that popup a little window with the current month, and let you
          click on the date.
          --
          - Tim Roberts, timr@probo.com
          Providenza & Boekelheide, Inc.

          Comment

          • Hansan

            #6
            Re: html tags and python

            Hi.

            Yeah I also like just to be able to write in numbers.
            That is how it works right now.

            But then I will have to make some code, that validates if the day number is
            higher than allowed.
            Like if it is January, the days arnt allowed to be higher than 31.

            Will one be so kind and explain how I write that code:
            Right now, the user has to put the data into a form:

            print '''<form action='inserte vent.py'><br>
            <p>Title :<br> <INPUT type="text" NAME="title">
            <p>Month (1-12):<br> <INPUT type="text" NAME="month">
            <p>Day (1-31):<br> <INPUT type="text" NAME="day">
            <p>Start (00.00):<br> <INPUT type="text" NAME="start"></p>
            <p>End (00.00):<br> <INPUT type="text" NAME="eventend" ></p>'''

            print '''<p><input type=submit value='Submit'> </p></form>'''
            print '''</body> </html>'''

            Then it runs the insertevent.py script, which puts the data into my
            database.(Using postgresql)

            form = cgi.FieldStorag e()
            title = form["title"].value
            month = form["month"].value
            day = form["day"].value
            start= form["start"].value
            eventend = form["eventend"].value

            insert_command = "INSERT INTO events1(title, maanedid, dage1id, start,
            eventend) VALUES('%s', '%s', '%s', '%s' , '%s')" %(title, month, day, start,
            eventend)
            cur.execute(ins ert_command)

            insert_command2 = "SELECT events1.eventsi d FROM events1 WHERE events1.title
            = '%s' AND events1.maanedi d = '%s' AND events1.dage1id = '%s' AND
            events1.eventst art = '%s' AND events1.eventen d = '%s'" %(title, month, day,
            eventstart, eventend)
            cur.execute(ins ert_command2)
            res = cur.fetchall()
            new_idevents = res[0][0]

            insert_command3 = " INSERT INTO evr1 (eventsid, maanedid, dage1id) VALUES
            ( '%s', '%s', '%s')" %(new_idevents, month, day)
            cur.execute(ins ert_command3)

            connect.commit( )
            cur.close()
            connect.close()
            print "<br>Arrangemen etet er nu oprettet."
            print "</form></body> </html>"

            Im which scritp, and how do I make an error message if the day is out of
            range.

            It is prolly something like:

            if month = 1
            then days have to be >1 and < 32
            else print " day entered out of range"
            if month = 2
            and so on...

            Thanks for all your help, somehow it just makes more sense when I see it, I
            am still new to the whole code thing :)

            Thanks


            "Tim Roberts" <timr@probo.com > wrote in message
            news:li9a41l4oi o4hhvjus8m2gn27 o33mcvedk@4ax.c om...[color=blue]
            > "Hansan" <none> wrote:[color=green]
            >>
            >>Hi all
            >>
            >>I am making something for my webpage
            >>
            >>Where the user can choose a month: I have made that with a dropdown box.
            >>
            >> <select>
            >> <option name = "1" value="1">Janua ry
            >> <option name = "2" value="2">Febru ary
            >> <option name = "3" value="3">March
            >> <option name = "4" value="4">April
            >> <option name = "5" value="5">May
            >> <option name = "6" value="6">June
            >> <option name = "7" value="7">July
            >> <option name = "8" value="8">Augus t
            >> <option name = "9" value="9">Septe mber
            >> <option name = "10" value="10">Octo ber
            >> <option name = "11" value="11">Nove mber
            >> <option name = "12" value="12">Dece mber
            >> </select>
            >>
            >>The thing is:
            >>I also want the user to choose a date
            >>I will make this with another dropdownbox.
            >>But if the first month is selected, then there should be 31 days in the
            >>days
            >>dropdownbox , if the second month is selected there should be 28 days in
            >>the
            >>dropdownbow .[/color]
            >
            > What if the year is 2004? Then I assume you want 29 days in the listbox.
            > And that, of course, means they have to choose the year first.
            >
            > This can be done, but it's a lot of trouble. You might consider allowing
            > 1
            > to 31 and validating the numbers in your "onSubmit" handler.
            >
            > Or, even better, skip the listbox and just let me type the damn numbers
            > myself. I hate being forced to fall back to my mouse to type in a date,
            > when I can type "3 tab 25 tab 2005" much quicker. To do that with your
            > code, I have to type "m tab 2 2 2 2 2 2 tab 2005".
            >
            > As an alternative, there are Javascript-based mini-calendars you can
            > download that popup a little window with the current month, and let you
            > click on the date.
            > --
            > - Tim Roberts, timr@probo.com
            > Providenza & Boekelheide, Inc.[/color]


            Comment

            • Patrik Andreasen

              #7
              Re: html tags and python

              Hansan wrote:[color=blue]
              > Hi.
              >
              > Yeah I also like just to be able to write in numbers.
              > That is how it works right now.
              >
              > But then I will have to make some code, that validates if the day number is
              > higher than allowed.
              > Like if it is January, the days arnt allowed to be higher than 31.
              >
              > Will one be so kind and explain how I write that code:[/color]

              Just use the datetime module:

              Python 2.4.1a0 (#2, Mar 1 2005, 15:45:39)
              [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
              Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
              >>> from datetime import date
              >>> date(2004, 2, 29)[/color][/color][/color]
              datetime.date(2 004, 2, 29)[color=blue][color=green][color=darkred]
              >>> date(2005, 2, 29)[/color][/color][/color]
              Traceback (most recent call last):
              File "<stdin>", line 1, in ?
              ValueError: day is out of range for month[color=blue][color=green][color=darkred]
              >>>[/color][/color][/color]

              /patrik

              Comment

              • gene.tani@gmail.com

                #8
                Re: html tags and python

                get the mx package here:
                eGenix.com is specialized in high-performance, professional quality Python database products and extensions.

                =============== =============== ===========[color=blue][color=green][color=darkred]
                >>> import mx.DateTime
                >>> print mx.DateTime.Dat eTime(2004,2,31 ) # Feb. 31?[/color][/color][/color]
                Traceback (most recent call last):
                File "<stdin>", line 1, in ?
                mx.DateTime.Ran geError: day out of range: 31[color=blue][color=green][color=darkred]
                >>>[/color][/color][/color]

                Comment

                • Hansan

                  #9
                  Re: html tags and python

                  Hi and thanks for the replies.

                  It is starting to make a little sense. But its still not that clear...

                  If I import the DateTime or install and import the mx package.
                  Where should I then change something in my code?
                  I guess that I will have to see if the entered number is valid when the user
                  clicks the submit button.
                  So it must be when I run my insertevent.py script.
                  So will I have to import the DateTime modul in my form.script or in my
                  insertevent.scr ipt

                  And this maybe sound stupid, but will one pls give me an example of what the
                  code could be for maybe January and February.

                  I just cant figure out how they work together, the DateTime modul and the
                  html form.
                  The user can enter a number in the month field and in the day field. Then
                  there have to be a tjeck to see if the entered numbers are valid. If the
                  number entered in the month field is 1 and the number entered in the day
                  field is 32, there have to come anerror report, and the user will get a
                  second try to enter the right numbers.

                  And then if the entered numbers are correct, the data will be inserted in
                  the database ( But I will work on this if condition myself, I think I can
                  figure that out:)

                  So it is just the tjeck to see if the entered numer are valid, I need help
                  with.

                  Thanks for all help, it is highly appreciated, and helps me to understand
                  this new strange but fascinating world of programming.








                  <gene.tani@gmai l.com> wrote in message
                  news:1111837773 .193649.94920@g 14g2000cwa.goog legroups.com...[color=blue]
                  > get the mx package here:
                  > http://www.egenix.com/files/python/e...ownload-mxBASE
                  > =============== =============== ===========[color=green][color=darkred]
                  >>>> import mx.DateTime
                  >>>> print mx.DateTime.Dat eTime(2004,2,31 ) # Feb. 31?[/color][/color]
                  > Traceback (most recent call last):
                  > File "<stdin>", line 1, in ?
                  > mx.DateTime.Ran geError: day out of range: 31[color=green][color=darkred]
                  >>>>[/color][/color]
                  >[/color]


                  Comment

                  • gene.tani@gmail.com

                    #10
                    Re: html tags and python



                    really good tutorial on exceptions. The whole book is well done, in
                    fact, I recommend it. I also like Practical Python, and the Oreilly
                    "Learning Python", but they're not online.

                    For production purposes, you'd still do date-check on the client
                    (javascript) but you must do the check server-side nevertheless.

                    Comment

                    • EP

                      #11
                      Re: html tags and python

                      [color=blue]
                      > <select>
                      > <option name = "1" value="1">Janua ry
                      > <option name = "2" value="2">Febru ary
                      > <option name = "3" value="3">March
                      > <option name = "4" value="4">April
                      > <option name = "5" value="5">May
                      > <option name = "6" value="6">June
                      > <option name = "7" value="7">July
                      > <option name = "8" value="8">Augus t
                      > <option name = "9" value="9">Septe mber
                      > <option name = "10" value="10">Octo ber
                      > <option name = "11" value="11">Nove mber
                      > <option name = "12" value="12">Dece mber
                      > </select>
                      >
                      > The thing is:
                      > I also want the user to choose a date
                      > I will make this with another dropdownbox.
                      > But if the first month is selected, then there should be 31 days in the
                      > days
                      > dropdownbox, if the second month is selected there should be 28 days in
                      > the
                      > dropdownbow.[/color]


                      Python is great, but I'd suggest trying this with JavaScript and the DOM (Document Object Model). In fact you may be able to Google-up a JavaScript script that does what you want. JavaScript executes on the client machine, which is perfect for that aspect of your application.

                      The general idea would be to have the script redefine the option values fordays upon selection of the year and month. The DOM lets you access those <option>s at run time very easily.

                      JavaScript is not as robust a programming language as Python, but it is handy for executing certain functionality within a browser interface, and because it works within the browser and can access the DOM, there is an elementof instant gratification.

                      Then... about the time you start to try to build a real application with JavaScript, it will start to drive you mad... and you will have a new, greater affection for Python.

                      Comment

                      • Jeremy Bowers

                        #12
                        Re: html tags and python

                        On Sat, 26 Mar 2005 18:07:01 -0800, EP wrote:[color=blue]
                        > Then... about the time you start to try to build a real application with
                        > JavaScript, it will start to drive you mad... and you will have a new,
                        > greater affection for Python.[/color]

                        Actually, if you dig into it really hard, it's not bad. In fact of all the
                        languages I know, Javascript is probably the closest to Python circa 1.5.2
                        that I can think of. Not identical, and it doesn't have *any* of the later
                        nice things in Python (metaclasses, descriptors, list comprehensions,
                        etc.), the OO can be clumsy (though it is fairly functional), and there
                        are inconveniences that I really wish I could make go away, but it's not
                        too bad.

                        (The worst being that

                        for (var something in someArray) {}

                        gives you the *indices* of the array, not the values, so the next line is
                        almost always

                        var theActualStinki ngValue = someArray[something];

                        ..)

                        The DOM is clumsy, but for any given browser not to bad. The *differences*
                        in the DOMs from browser to browser are what kill you. And of course, no
                        real "libraries" .

                        Comment

                        • Hansan

                          #13
                          Re: html tags and python

                          Hi and thanks for your replies.

                          Will one still tell me how I use the timedate modul with my form

                          print '''<form action='inserte vent.py'><br>
                          <p>Day (1-31):<br> <INPUT type="text" NAME="day">
                          <p>Month (1-12):<br> <INPUT type="text" NAME="month">
                          print '''<p><input type=submit value='Submit'> </p></form>'''


                          ------------------------------------------------------------------------------------------
                          It is starting to make a little sense. But its still not that clear...

                          If I import the DateTime or install and import the mx package.
                          Where should I then change something in my code?
                          I guess that I will have to see if the entered number is valid when the user
                          clicks the submit button.
                          So it must be when I run my insertevent.py script.
                          So will I have to import the DateTime modul in my form.script or in my
                          insertevent.scr ipt

                          And this maybe sound stupid, but will one pls give me an example of what the
                          code could be for maybe January and February.

                          I just cant figure out how they work together, the DateTime modul and the
                          html form.
                          The user can enter a number in the month field and in the day field. Then
                          there have to be a tjeck to see if the entered numbers are valid. If the
                          number entered in the month field is 1 and the number entered in the day
                          field is 32, there have to come anerror report, and the user will get a
                          second try to enter the right numbers.

                          And then if the entered numbers are correct, the data will be inserted in
                          the database ( But I will work on this if condition myself, I think I can
                          figure that out:)


                          "Jeremy Bowers" <jerf@jerf.or g> wrote in message
                          news:pan.2005.0 3.27.02.24.59.7 54912@jerf.org. ..[color=blue]
                          > On Sat, 26 Mar 2005 18:07:01 -0800, EP wrote:[color=green]
                          >> Then... about the time you start to try to build a real application with
                          >> JavaScript, it will start to drive you mad... and you will have a new,
                          >> greater affection for Python.[/color]
                          >
                          > Actually, if you dig into it really hard, it's not bad. In fact of all the
                          > languages I know, Javascript is probably the closest to Python circa 1.5.2
                          > that I can think of. Not identical, and it doesn't have *any* of the later
                          > nice things in Python (metaclasses, descriptors, list comprehensions,
                          > etc.), the OO can be clumsy (though it is fairly functional), and there
                          > are inconveniences that I really wish I could make go away, but it's not
                          > too bad.
                          >
                          > (The worst being that
                          >
                          > for (var something in someArray) {}
                          >
                          > gives you the *indices* of the array, not the values, so the next line is
                          > almost always
                          >
                          > var theActualStinki ngValue = someArray[something];
                          >
                          > .)
                          >
                          > The DOM is clumsy, but for any given browser not to bad. The *differences*
                          > in the DOMs from browser to browser are what kill you. And of course, no
                          > real "libraries" .[/color]


                          Comment

                          • Swaroop C H

                            #14
                            Re: html tags and python

                            On Sat, 26 Mar 2005 01:13:08 +0100, Hansan <none@bag.pytho n.org> wrote:[color=blue]
                            > Do you know what I should google after, which key words ?[/color]

                            "free javascript calendar"

                            These look interesting:
                            http://www.scriptsearch.com/JavaScri...pts/Calendars/
                            Ozzu is a trusted online community and market where developers can ask questions, learn new skills, share knowledge, and buy and sell digital assets.


                            IMHO, using Javascript is a better idea for this particular purpose
                            instead of writing a lot of checking in Python.

                            --
                            Swaroop C H
                            Blog: http://www.swaroopch.info
                            Book: http://www.byteofpython.info

                            Comment

                            • Hansan

                              #15
                              Re: html tags and python

                              I figured it out with a lot of if else statements, but still if one have
                              time to explain how the time/date modul works with forms, I will be more
                              than happy to lear.

                              Thanks


                              "Hansan" <none> wrote in message
                              news:4247bc82$0 $22679$ba624c82 @nntp04.dk.teli a.net...[color=blue]
                              > Hi and thanks for your replies.
                              >
                              > Will one still tell me how I use the timedate modul with my form
                              >
                              > print '''<form action='inserte vent.py'><br>
                              > <p>Day (1-31):<br> <INPUT type="text" NAME="day">
                              > <p>Month (1-12):<br> <INPUT type="text" NAME="month">
                              > print '''<p><input type=submit value='Submit'> </p></form>'''
                              >
                              >
                              > ------------------------------------------------------------------------------------------
                              > It is starting to make a little sense. But its still not that clear...
                              >
                              > If I import the DateTime or install and import the mx package.
                              > Where should I then change something in my code?
                              > I guess that I will have to see if the entered number is valid when the
                              > user
                              > clicks the submit button.
                              > So it must be when I run my insertevent.py script.
                              > So will I have to import the DateTime modul in my form.script or in my
                              > insertevent.scr ipt
                              >
                              > And this maybe sound stupid, but will one pls give me an example of what
                              > the
                              > code could be for maybe January and February.
                              >
                              > I just cant figure out how they work together, the DateTime modul and the
                              > html form.
                              > The user can enter a number in the month field and in the day field. Then
                              > there have to be a tjeck to see if the entered numbers are valid. If the
                              > number entered in the month field is 1 and the number entered in the day
                              > field is 32, there have to come anerror report, and the user will get a
                              > second try to enter the right numbers.
                              >
                              > And then if the entered numbers are correct, the data will be inserted in
                              > the database ( But I will work on this if condition myself, I think I can
                              > figure that out:)
                              >
                              >
                              > "Jeremy Bowers" <jerf@jerf.or g> wrote in message
                              > news:pan.2005.0 3.27.02.24.59.7 54912@jerf.org. ..[color=green]
                              >> On Sat, 26 Mar 2005 18:07:01 -0800, EP wrote:[color=darkred]
                              >>> Then... about the time you start to try to build a real application with
                              >>> JavaScript, it will start to drive you mad... and you will have a new,
                              >>> greater affection for Python.[/color]
                              >>
                              >> Actually, if you dig into it really hard, it's not bad. In fact of all
                              >> the
                              >> languages I know, Javascript is probably the closest to Python circa
                              >> 1.5.2
                              >> that I can think of. Not identical, and it doesn't have *any* of the
                              >> later
                              >> nice things in Python (metaclasses, descriptors, list comprehensions,
                              >> etc.), the OO can be clumsy (though it is fairly functional), and there
                              >> are inconveniences that I really wish I could make go away, but it's not
                              >> too bad.
                              >>
                              >> (The worst being that
                              >>
                              >> for (var something in someArray) {}
                              >>
                              >> gives you the *indices* of the array, not the values, so the next line is
                              >> almost always
                              >>
                              >> var theActualStinki ngValue = someArray[something];
                              >>
                              >> .)
                              >>
                              >> The DOM is clumsy, but for any given browser not to bad. The
                              >> *differences*
                              >> in the DOMs from browser to browser are what kill you. And of course, no
                              >> real "libraries" .[/color]
                              >
                              >[/color]


                              Comment

                              Working...