3 Replies - 401 Views - Last Post: 28 February 2010 - 01:10 PM

#1 XMEGA  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 17-November 08

validation javascript

Posted 28 February 2010 - 12:23 PM

Hi, instead of showing a alert/messageBox how do I just change the text in an empty label or textbox? after the user clicks sumbit?

<script language="Javascript">
function validate(form)
{
    if (form.code.value=="")
    {
        alert("You must enter a code for the book.");
        form.code.focus();
    }
    else if (form.description.value=="")
    {
        alert("You must enter a description for the book.");
        form.description.focus();
    }
    else if (form.quantity.value=="")
    {
        alert("You must enter a positive number for the quantity.")
        form.quantity.focus();
    }
    else
    {
        form.submit();
    }
}
</script>



I want something like this
if (form.code.value=="")
{
form.code.value=="Enter Code";
form.code.focus();

Is This A Good Question/Topic? 0
  • +

Replies To: validation javascript

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1619
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: validation javascript

Posted 28 February 2010 - 12:26 PM

Moved to Javascript. Javascript is not Java
Was This Post Helpful? 0
  • +
  • -

#3 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 921
  • View blog
  • Posts: 6,456
  • Joined: 07-September 06

Re: validation javascript

Posted 28 February 2010 - 12:44 PM

form.code.value=="Enter Code";


The problem here is that you are using the equality operator instead of the equals operator (double = instead of a single =), so if you do this:
form.code.value = "Enter Code";

it should work.

Hope that helps.
Was This Post Helpful? 1
  • +
  • -

#4 williamgeorgegardner  Icon User is offline

  • CEO of GeekTelligence
  • member icon

Reputation: 19
  • View blog
  • Posts: 584
  • Joined: 27-December 09

Re: validation javascript

Posted 28 February 2010 - 01:10 PM

Please put all your code inside [ code ] tags [ / code ] it just makes it easier to read and better for future reference.

Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1