Solved

Implementing HTML page actions without javascript

Posted on 2014-11-26
4
200 Views
Last Modified: 2014-11-27
I have a single HTML page with a form generated by a web server running Python CGI scripts.  I have been asked to have the page change its display to respond to user errors - such as to highlight a field and place an error marker next to it - WITHOUT using Javascript.

Is there any way to do this without having the server CGI scripts receive the user’s responses to the form and craft a redisplay of the page with the HTML rebuilt to show the error marker (with the user’s filled in data)?

Here is the code:
def output_select_options(name,options,fields,rc=2):
    selected = fields.get(name,'') 
    selected = selected.strip()
    if debug:
      print "SELECTED " + selected
    if len(fields) > 0  and 'phase' in fields: # and fields['phase'] == "1":
      goforit = True
    else:
      goforit = False
    for value,text in options:
	if value==selected or text==selected:
          bar = 'selected="selected"'
	else:
	  bar = ""
        print '  <option value="%s" %s>%s</option>' % \
              (value,bar,text)
    if rc == 2:
      print '<script type="text/javascript">document.getElementById(\'%s\').innerHTML = "";</script>'% (name)
      url = os.environ["REQUEST_URI"]
      if debug:
        print url
      url = 'https://eecsappsrv.mit.edu/' + url
      if debug:
        print url
      valuestr =  urlparse(url).query
      if goforit and len(valuestr) > 0:
        fields[name] = urllib.unquote(valuestr)
      output_select_options(name,options,fields,1)

def output_select(name,options,fields):
    print '<td><select id= "%s" name="%s" value = "mysister" class="Required" onchange="usgsChanged(this);" >' % (name,name)
    output_select_options(name,options,fields);
    print '</select></td>'

Open in new window


-
0
Comment
Question by:camster123
  • 2
4 Comments
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 500 total points
ID: 40468906
The short answer is no.

Basically there are 2 ways of doing this, the old way and the new way.
The old way is as you need, no javascript, and for that you need to post the whole page, validate everything server-side and if there are errors you need to apply the CSS error classes directly to the rendering HTML elements and push it back to the client.

The "new" way is to post only the data to the server and on error reply with the list of errors and let javascript apply those error css classes to the elements.

So my friend, I'm afraid there's no magic for you :)

Cheers!
0
 

Author Closing Comment

by:camster123
ID: 40468927
Mr. Alexandre Simões2014-11-27 at 05:21:02ID: 40468906
    Please be patient with me
>>The old way is as you need, no javascript, and for that you need to post the whole page, validate everything server-side and if there are >>errors you need to apply the CSS error classes directly to the rendering HTML elements and push it back to the client.

Could you or someone please
     1) Rephrase this expert comment by  Alexandre Simões.
     2) show me a Python function prototypes  for show(.....) and reshow(.....)?
If I am unclear, my English is not that good, please let me know and I will fix it immediately.
Happy Thanksgiving! Cheers!
  frankc123
0
 

Author Comment

by:camster123
ID: 40468929
Mr. Alexandre Simões,
     Please be patient with me
 >>The old way is as you need, no javascript, and for that you need to post the whole page, validate everything server-side and if there are >>errors you need to apply the CSS error classes directly to the rendering HTML elements and push it back to the client.

 Could you or someone please
      1) Rephrase this expert comment by  Alexandre Simões.
      2) show me a Python function prototypes  for show(.....) and reshow(.....)?
 If I am unclear, my English is not that good, please let me know and I will fix it immediately.
 Happy Thanksgiving! Cheers!
   frankc123
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now