473,785 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Jul 18 '05 #1
15 1711
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
Thanks.

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

regards...
"Kane" <ja**********@g mail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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
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
"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">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.


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
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" <ti**@probo.com > wrote in message
news:li******** *************** *********@4ax.c om...
"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">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 .


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
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(2 004, 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
get the mx package here:
http://www.egenix.com/files/python/e...ownload-mxBASE
=============== =============== ===========
import mx.DateTime
print mx.DateTime.Dat eTime(2004,2,31 ) # Feb. 31? Traceback (most recent call last):
File "<stdin>", line 1, in ?
mx.DateTime.Ran geError: day out of range: 31


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


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

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2453
by: Leif K-Brooks | last post by:
I'm writing a site with mod_python which will have, among other things, forums. I want to allow users to use some HTML (<em>, <strong>, <p>, etc.) on the forums, but I don't want to allow bad elements and attributes (onclick, <script>, etc.). I would also like to do basic validation (no overlapping elements like <strong><em>foo</em></strong>, no missing end tags). I'm not asking anyone to write a script for me, but does anyone have general...
8
2925
by: Moosebumps | last post by:
Is there a standard solution for writing HTML web pages with Python? I don't know that much about web programming, but basically I want to generate some internal reports on a web page. It doesn't need to be fancy, just basic tables and linking, maybe indexing and navigation, but I want it to all look nice and I want to be able to change the formatting easily without combing through source code (hence my next question about CSS). I...
13
2395
by: Michele Simionato | last post by:
What is the recommended way of generating HTML from Python? I know of HTMLGen and of few recipes in the Cookbook, but is there something which is more or less standard? Also, are there plans to include a module for HTML generation in the standard library? I really would like to see some standardization in this area. Michele Simionato
7
2829
by: Ivan Voras | last post by:
Is there a HTML clean/tidy library or module written in pure python? I found mxTidy, but it's a interface to command-line tool. What I'm searching is something that will accept a list of allowed tags and/or attributes and strip the rest from HTML string.
10
3339
by: Sullivan WxPyQtKinter | last post by:
Hi, everyone. Simply put, what I need most now is a python lib to generate simple HTML. I am now using XML to store my lab report records. I found python really convinient to manipulate XML, so I want to make a small on-line CGI program to help my colleagues to build their lab report records into XML, for storage, HTML display (for others to browse) and search. With python's standard lib, the DOM object could realize the XML storage...
13
4244
by: DH | last post by:
Hi, I'm trying to strip the html and other useless junk from a html page.. Id like to create something like an automated text editor, where it takes the keywords from a txt file and removes them from the html page (replace the words in the html page with blank space) I'm new to python and could use a little push in the right direction, any ideas on how to implement this? Thanks!
3
6415
by: sebzzz | last post by:
Hi, I'm doing a little script with the help of the BeautifulSoup HTML parser and uTidyLib (HTML Tidy warper for python). Essentially what it does is fetch all the html files in a given directory (and it's subdirectories) clean the code with Tidy (removes deprecated tags, change the output to be xhtml) and than BeautifulSoup removes a couple of things that I don't want in the files (Because I'm stripping the files to bare bone, just...
11
4601
by: Tim Arnold | last post by:
hi, I've got lots of xhtml pages that need to be fed to MS HTML Workshop to create CHM files. That application really hates xhtml, so I need to convert self-ending tags (e.g. <br />) to plain html (e.g. <br>). Seems simple enough, but I'm having some trouble with it. regexps trip up because I also have to take into account 'img', 'meta', 'link' tags, not just the simple 'br' and 'hr' tags. Well, maybe there's a simple way to do that...
0
1112
by: John Krukoff | last post by:
-----Original Message----- One method which wouldn't require much python code, would be to run the XHTML through a simple identity XSL tranform with the output method set to HTML. It would have the benefit that you wouldn't have to worry about any of the specifics of the transformation, though you would need an external dependency. As far as I know, both 4suite and lxml (my personal favorite:
0
1116
by: M.-A. Lemburg | last post by:
On 2008-04-24 19:16, John Krukoff wrote: You could filter the XHTML through mxTidy and set the hide_endtags to 1: http://www.egenix.com/products/python/mxExperimental/mxTidy/ -- Marc-Andre Lemburg eGenix.com
0
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8978
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.