Web Design and Web Development Forum

  1. #1
    Join Date
    Jul 2010
    Posts
    1
    Rep Power
    0
  2. jamesnotjamie is on a distinguished road
  3. Post Form field required, JS

    Hi,

    I'm not massively experienced with JS, but have some experience with php so can read the code reasonably well.

    I'm looking to make both fields on my html form required, just a simple alert window would do the trick. I've tried a few simple examples, but they don't seem to work with my form, I think it's because I have a little JS in the form itself, which could be conflicting.

    Here is my form:

    Code:
    <form id="two" action=" " name=form method="post">
        <input name="email" id="email" type="text" value="E-Mail" onfocus="this.value=(this.value=='E-Mail') ? '' : this.value;" onblur="this.value=(this.value=='') ? 'E-Mail' : this.value;">
        <input name="city" id="city" type="text" value="City" onfocus="this.value=(this.value=='City') ? '' : this.value;" onblur="this.value=(this.value=='') ? 'City' : this.value;">    
      	<input id="button" type="submit" value="Get Free Track">
    	</form>
    I would like both fields to be required, like a say, a little alert would be just fine.

    The sources I read and tried (unsuccessfully) were:
    JavaScript Tip: Basic Form Validation With JavaScript
    The JavaScript Source: Forms: Required Fields
    Use JavaScript to Check Required HTML Form Fields

    Could anyone point me in the right direction?

    Thanks,
    James
    Reply With Quote Reply With Quote
  4. #2
    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0
  5. Darth Vader is on a distinguished road
  6. Exclamation Re: Form field required, JS

    :unsure: You shouldn't use JavaScript for validation. It's easily removable and editable with firebug, which equals over 9000 security problems. I would submit it as a form and have a server side scripting language such as PHP validate it. But that's me. :nerd:
    Reply With Quote Reply With Quote
  7. #3
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0
  8. crystalnepal is on a distinguished road
  9. Re: Form field required, JS

    Hey,

    For detailed information about computer sale and maintenance visit
    Crystal Techno & Computer Solutions Pvt Ltd

    This is the one of the best computer sale and maintenance company in Nepal. If you have any types of computer problem then there is complete solution of all problem. If you need any types of computer product then crystal Nepal provide you very easy way. Crystal Nepal sales all the product of computer.

    Hope I Could Help!
    Reply With Quote Reply With Quote

Similar Threads

  1. php : File Upload Form
    By geim in forum PHP Articles
    Replies: 4
    Last Post: 08-09-2007, 12:04 AM
  2. PHP Form Processing
    By alexeyre in forum PHP Articles
    Replies: 9
    Last Post: 04-24-2006, 07:06 PM
  3. Creating a "Splash" form
    By cipher_nemo in forum General Programming
    Replies: 1
    Last Post: 01-31-2006, 05:28 AM