I have been playing around with JavaScript and PHP in the last few days and have not bee able to get this to work;
I am trying to get a form that emails details as if it were a contact form on a website. the email bit was fine. the javascript i am trying to get to validate by simply checking that, for example a number is entered in telephone text box and that the default values are not in the text box's. they disappear once a user clicks on them. so far this is the form
JavaScript Code:
but i cant seem to get this to work. i am doing it all on one page, although doing a separate JS file is easier and would use that if i did this on an actual website
I am trying to get a form that emails details as if it were a contact form on a website. the email bit was fine. the javascript i am trying to get to validate by simply checking that, for example a number is entered in telephone text box and that the default values are not in the text box's. they disappear once a user clicks on them. so far this is the form
JavaScript Code:
PHP:
<form name="quotePrice" method="post" action="../scripts/emailQuote.php">
<input type="text" name="name" size="30" value="name" class="mainDivContentBottomFormName" id="name" onclick="if(this.value=='name'){this.value=''};"
onchange="if(document.getElementById('name')=='name' || document.getElementById('phoneNumber')=='phone number' || document.getElementById('email')=='email'){
document.getElementById('theButton').disabled=false
}
else{
document.getElementById('theButton').disabled=true
};" />
<input type="text" name="phoneNumber" size="30" class="mainDivContentBottomFormPhoneNumber" id="phoneNumber" value="phone number"
onclick="if(this.value=='phone number'){
this.value=''
};"
onchange="if(document.getElementById('name')=='name' || document.getElementById('phoneNumber')=='phone number' || document.getElementById('email')=='email'){
document.getElementById('theButton').disabled=false
}
else{
document.getElementById('theButton').disabled=true
};
if(isNaN(document.getElementById('phoneNumber').value)){
alert('please enter a valid phone number, although it is not required.')
};" />
<input type="text" name="email" size="30" class="mainDivContentBottomFormEmail" id="email" value="email address"
onclick="if(this.value=='email address'){
this.value=''
};"
onchange="if(document.getElementById('name')=='name' || document.getElementById('phoneNumber')=='phone number' || document.getElementById('email')=='email'){
document.getElementById('theButton').disabled=false
}
else{
document.getElementById('theButton').disabled=true
};" />
<textarea name="comment" cols="30" rows="4" class="mainDivContentBottomFormComment"></textarea>
<input type="submit" value="get me a quote!" class="mainDivContentBottomFormButton" id="theButton" disabled="disabled" />
</form>
but i cant seem to get this to work. i am doing it all on one page, although doing a separate JS file is easier and would use that if i did this on an actual website