Thursday, 5 September 2013

JS form check empty

JS form check empty

Hi I want to check a form if the input values are empty but i'm not sure
whats the best way to do this is, so i tried this:
function checkform()
{
if (document.getElementById("promotioncode").value == "")
{
// something is wrong
alert('There is a problem with the first field');
return false;
}
return true;
}
html:
<form id="orderForm" onSubmit="return checkform()">
<input name="promotioncode" id="promotioncode" type="text" />
<input name="price" id="price" type="text" value="&euro; 15,00"
readonly="readonly"/>
<input class="submit" type="submit" value="Submit"/>
</form>
Has anybody an idea or some kind of an better solution ? thx for any help :)

No comments:

Post a Comment