Forum Moderators: open

Message Too Old, No Replies

hi need help with HTML form and javascript

Html Javascript

         

dskaushik5

10:07 pm on Mar 28, 2003 (gmt 0)

10+ Year Member



hi I have this code but when i run it it gives me run time error where i have defined the Form . It says Object expected.

Will appreciate any help.

<script language="Javascript/text">
function checkForm(myForm)
{
var thisForm = myForm;
If (thisForm.selectBooks.value=="")
{
return();
}
else
thisForm.submit();

}
</script>

//error is here It says object expected?
<FORM name="AABooks" method="post" action="sell_Books.php;">
<p>
<SELECT name="selectBooks" onChange="checkForm(document.AABooks);" style="font-size='13px'; font-family='MS Sans Serif'; font-weight=500; font-style='Normal'; text-decoration='None'; width=">
<OPTION value="" SELECTED style="background-color='';color=''">Select
<OPTION value="">-----------------------------

thanks

txbakers

1:00 am on Mar 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<script language="Javascript/text">
function checkForm(myForm)
{
If (myForm.selectBooks.value=="")
{
return false;
} else {
myForm.submit();

}
</script>

It looks like you left out the curly bracket in red above.

g1smd

1:49 am on Mar 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That can't be right as you now have 3 x { and only 2 x } brackets.

I'm no javscript expert, but I can recognise uneven nesting when I see it.

txbakers

5:33 am on Mar 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



function checkForm(myForm)
{
If (myForm.selectBooks.value=="") return false
else myForm.submit();
}

Try that one.

You might need a semi-colon after the false above, might not. don't remember.

Carswell

9:55 am on Mar 29, 2003 (gmt 0)

10+ Year Member



I have looked at your code and I am assuming that you want people to be able to select numbers of products, and then have the form checked to make sure that at least one field has been completed before it is submitted?

Take a look at this page and see if this will do the trick - just cut and paste the whole thing, make an html page out of it and and view it in the browser. Is this what you are tying to achieve? I hope this helps.

Code from here on>>

<html>
<head>
<title></title>
<script language="javascript1.2" type="text/javascript">
function checkForm(){
field1=document.AABooks.product1;
field2=document.AABooks.product2;
if (field1.value=="" && field2.value==""){
alert("You have submitted an empty form. please make a selection");
return false;
}
}
</script>
</head>
<body>
<form name="AABooks" method="post" onsubmit="return checkForm()" action="sell_Books.php;">
<p>
Insert number of products required:
</p>
<p>
Select product number 1: <input type="text" name="product1" size="2" maxlength="2" value="">
</p>
<p>
Select product number 2: <input type="text" name="product2" size="2" maxlength="2" value="">
</p>
<input type="submit" value="Submit">
</form>
</body>
</html>