1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

HTML DOM, Javascript Question

Discussion in 'Programming & Webmastering' started by ct5098, Dec 24, 2010.

  1. ct5098 New Member

    Joined:
    Aug 3, 2009
    Messages:
    13 (0.01/day)
    Thanks Received:
    0
    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. temp02 New Member

    Joined:
    Mar 18, 2009
    Messages:
    493 (0.25/day)
    Thanks Received:
    166
    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. ct5098 New Member

    Joined:
    Aug 3, 2009
    Messages:
    13 (0.01/day)
    Thanks Received:
    0
    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. temp02 New Member

    Joined:
    Mar 18, 2009
    Messages:
    493 (0.25/day)
    Thanks Received:
    166
    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. ct5098 New Member

    Joined:
    Aug 3, 2009
    Messages:
    13 (0.01/day)
    Thanks Received:
    0
    Ok, thanks for your help. I always try to do things the hard way :)
  6. W1zzard

    W1zzard Administrator Staff Member

    Joined:
    May 14, 2004
    Messages:
    14,647 (3.92/day)
    Thanks Received:
    11,389
    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. ct5098 New Member

    Joined:
    Aug 3, 2009
    Messages:
    13 (0.01/day)
    Thanks Received:
    0
    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 guest)

Share This Page