Jump to content

form validation driving me nuts


gazever

Recommended Posts

Hi Im really a PHP programmer and trying to cobble together some code for a very simple form validation, what i need to do is if a select value is at its default state of "Choose size" I need to make an alert saying choose size before sending the form.

 

In IE it keeps saying this page contains errors "object doesnt support this method or property "but functions ok, however this is stopping me from adding another zooming in javascript for images.

 

Could someone Please amend or let me know what im doing wrong.

 

in the head

<script type="text/javascript">
function submitform(){
var sizevar = document.getElementById("size");
if(!madeSelection(sizevar, "Please Choose a Size")){

}
}
function madeSelection(elem, helperMsg){
if(elem.value == "choose"){
	alert(helperMsg);
	elem.focus();
	return false;
}else{
	document.addtocart.submit();
}
}
</script>

 

bit of a mismatch of code, dont know javascript

 

and the link to submit the form

 

<a href="javascript: submitform()" class="buy">Add to shopping bag</a>

 

Thanks!

 

Link to comment
Share on other sites

if anyones interested here final working code, however IE8 doesnt show the alert message, anyone know why?

 

<script type="text/javascript">
function submitform(){
var selectedvalue = document.getElementById("size") ;
if(selectedvalue.value == "choose"){
	alert("Please choose a size");
} else {
	document.addtocart.submit();
}

}
</script>

<a href="javascript:submitform()" class="buy">Add to shopping bag</a>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.