By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,172 Members | 727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,172 IT Pros & Developers. It's quick & easy.

html tags and python

P: n/a
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">January
<option name = "2" value="2">February
<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">August
<option name = "9" value="9">September
<option name = "10" value="10">October
<option name = "11" value="11">November
<option name = "12" value="12">December
</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

Jul 18 '05 #1
Share this Question
Share on Google+
15 Replies


P: n/a
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.

Jul 18 '05 #2

P: n/a
Thanks.

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

regards...
"Kane" <ja**********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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.

Jul 18 '05 #3

P: n/a
Kane wrote:
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.


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.

Jul 18 '05 #4

P: n/a
"Hansan" <none> wrote:

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">January
<option name = "2" value="2">February
<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">August
<option name = "9" value="9">September
<option name = "10" value="10">October
<option name = "11" value="11">November
<option name = "12" value="12">December
</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.


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, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #5

P: n/a
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='insertevent.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.FieldStorage()
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(insert_command)

insert_command2 = "SELECT events1.eventsid FROM events1 WHERE events1.title
= '%s' AND events1.maanedid = '%s' AND events1.dage1id = '%s' AND
events1.eventstart = '%s' AND events1.eventend = '%s'" %(title, month, day,
eventstart, eventend)
cur.execute(insert_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(insert_command3)

connect.commit()
cur.close()
connect.close()
print "<br>Arrangemenetet 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" <ti**@probo.com> wrote in message
news:li********************************@4ax.com...
"Hansan" <none> wrote:

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">January
<option name = "2" value="2">February
<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">August
<option name = "9" value="9">September
<option name = "10" value="10">October
<option name = "11" value="11">November
<option name = "12" value="12">December
</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.


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, ti**@probo.com
Providenza & Boekelheide, Inc.

Jul 18 '05 #6

P: n/a
Hansan wrote:
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:


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.
from datetime import date
date(2004, 2, 29) datetime.date(2004, 2, 29) date(2005, 2, 29) Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: day is out of range for month


/patrik

Jul 18 '05 #7

P: n/a
get the mx package here:
http://www.egenix.com/files/python/e...ownload-mxBASE
=========================================
import mx.DateTime
print mx.DateTime.DateTime(2004,2,31) # Feb. 31? Traceback (most recent call last):
File "<stdin>", line 1, in ?
mx.DateTime.RangeError: day out of range: 31


Jul 18 '05 #8

P: n/a
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.script

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.


<ge*******@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
get the mx package here:
http://www.egenix.com/files/python/e...ownload-mxBASE
=========================================
import mx.DateTime
print mx.DateTime.DateTime(2004,2,31) # Feb. 31? Traceback (most recent call last):
File "<stdin>", line 1, in ?
mx.DateTime.RangeError: day out of range: 31

Jul 18 '05 #9

P: n/a
http://diveintopython.org/file_handling/index.html

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.

Jul 18 '05 #10

P: n/a
EP
<select>
<option name = "1" value="1">January
<option name = "2" value="2">February
<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">August
<option name = "9" value="9">September
<option name = "10" value="10">October
<option name = "11" value="11">November
<option name = "12" value="12">December
</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.

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.

Jul 18 '05 #11

P: n/a
On Sat, 26 Mar 2005 18:07:01 -0800, EP wrote:
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.


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 theActualStinkingValue = 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".
Jul 18 '05 #12

P: n/a
Hi and thanks for your replies.

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

print '''<form action='insertevent.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.script

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" <je**@jerf.org> wrote in message
news:pa****************************@jerf.org...
On Sat, 26 Mar 2005 18:07:01 -0800, EP wrote:
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.


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 theActualStinkingValue = 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".

Jul 18 '05 #13

P: n/a
On Sat, 26 Mar 2005 01:13:08 +0100, Hansan <no**@bag.python.org> wrote:
Do you know what I should google after, which key words ?


"free javascript calendar"

These look interesting:
http://www.scriptsearch.com/JavaScri...pts/Calendars/
http://www.bigwebmaster.com/JavaScri...ams/Calendars/

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
Jul 18 '05 #14

P: n/a
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:42***********************@nntp04.dk.telia.net ...
Hi and thanks for your replies.

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

print '''<form action='insertevent.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.script

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" <je**@jerf.org> wrote in message
news:pa****************************@jerf.org...
On Sat, 26 Mar 2005 18:07:01 -0800, EP wrote:
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.


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 theActualStinkingValue = 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".


Jul 18 '05 #15

P: n/a
Hansan wrote:
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 this isn't the solution to your problem (the solution would be to use
JavaScript), but if I was a user, I'd rather type in the day number myself than
have to choose from a 31-long dropdown. Why don't you just give the user a text
field and then validate the input.

Just my 2 cents..

--
Timo Virkkala
Jul 18 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.