![]() |
|
|
#1 |
![]() |
HTML DOM, Javascript Question
I'm creating a web-based inventory management system for a computer repair store. I want to have the user click a button and create a form underneath the button. If I create the form via Javascript with createElement, appendChild, etc. will I be able to access the ids within the newly created form and provide client-side validation with Javascript? Right now I'm using AJAX to get the form from a PHP script where I just echo the HTML code; then I just use innerHTML to insert the code onto the page. I can't use Javascript to validate the form the way I do it now.
|
|
|
|
|
|
#2 |
![]() Join Date: Mar 2009
Posts: 490 (0.32/day)
Thanks: 0
Thanked 171 Times in 158 Posts
|
How about setting the default size of the Form to 0 (CSS height) and when the button is pressed the form is shown (height property removed or returned to default size, you could even animate the sucker if you want)?
As for the validation it has to occur in the server when the POST of the form is submited, you could validate it with javascript but some smartguy could still submit "wrong" values. Please note that it has been a while since I've messed with any web stuff :P. |
|
|
|
|
|
#3 |
![]() |
I was thinking of doing something with CSS, except with the visibility property. Wil this work if I just change the visibility of the form to hidden and then visible? I was only just starting to learn AJAX and I just wanted to use it to see how it would work.
|
|
|
|
|
|
#4 |
![]() Join Date: Mar 2009
Posts: 490 (0.32/day)
Thanks: 0
Thanked 171 Times in 158 Posts
|
AFAIK yes you can change the css "visibility" property to "hidden" or "visible" and the form should act accordingly.
It's easier this way, since it's just one or two lines of Javascript to show and hide the form. |
|
|
|
|
|
#5 |
![]() |
Ok, thanks for your help. I always try to do things the hard way
|
|
|
|
|
|
#6 |
|
Benevolent Dictator
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 13,869 (4.17/day)
Thanks: 184
Thanked 10,450 Times in 3,218 Posts
|
if the form is static you should hide it via css visibility
if you need to generate its contents on user action, use ajax to generate the html code and insert it in appropriate position, this should update the DOM tree. dont forget about server side validation. never ever trust the client with anything, it's incredibly easy to modify/remove/generate html and js code personally i avoid js whereever possible or at least make sure there's a decent fallback for client without js enabled that makes sure everything stays usable |
|
|
|
|
|
#7 |
![]() |
Yes, the form is static. I am going to have to validate with PHP as well trio check the MySQL database to ensure no duplicate entries, etc. Thanks for the responses.
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Official HTML(4,5) and javascript users help thread. | Braveheart | Programming & Webmastering | 11 | Dec 21, 2009 05:32 PM |
| some html php and mysql mixed question | r9 | Programming & Webmastering | 2 | Aug 30, 2009 04:24 PM |
| quick HTML question | Braveheart | Programming & Webmastering | 3 | Jul 5, 2009 08:42 AM |