PDA

View Full Version : Validation AND submit AND next id.


matola
03-29-2007, 04:40 PM
Hi Many many thanks in advance for any help in this, total jscript newbie, eyes and fingers tired of hacking at it,, i think i got close.


I have been using a simple code to submit my form and go to next page.

<FORM action=default.asp name=frmEditItem id=frmEditItem method=POST>
<INPUT type=hidden name=ACTION value=SAVEITEM>
<INPUT type=hidden name=V_ITEM_ID value='531'>
<H2>Your info</h2>[%ITEM;#LASTCREATED|5#;182 183 184;;;<table cellpadding=0 cellspacing=0 class=form>;</table>;<tr><td>#FIELDNAME:</td><td>#FIELDINPUT#</td></tr>%]<input type="button" onclick="frmSubmit();" value="Join So Esteem website"></form>

<SCRIPT>
function frmSubmit() {
document.frmEditItem.V_ITEM_ID.value='531';
document.frmEditItem.submit();
}
</SCRIPT>

You see my form fields are dynamicly create from asp.
This has been working fine for me.

Now i try to add validation like:-

<script language="JavaScript" type="text/javascript">
function checkform (frmEditItem){

if(frmEditItem.F182.value == "") {
alert( "Please fill out your first name." );
frmEditItem.F182.focus();
return false ;
}
if(frmEditItem.F183.value == "") {
alert( "Please fill out your surname." );
frmEditItem.F183.focus();
return false ;
}

if(frmEditItem.F184.value == "") {
alert( "Please fill out your email address." );
frmEditItem.F184.focus();
return false ;
}
if(frmEditItem.F184.value.indexOf("@") < 0){
alert("Please use a valid email address.");
frmEditItem.F184.focus();
return false;
}
if(frmEditItem.F184.value.indexOf(".") < 0){
alert("Please use a valid email address.");
frmEditItem.F184.focus();
return false;
}
return true;
{
document.frmEditItem.V_ITEM_ID.value='531';
document.frmEditItem.submit();
}
}

</script>

<table width=400 height=400><tr><td valign=top><H2>Join us</H2>
<FORM action=default.asp name=frmEditItem id=frmEditItem method=POST>
<INPUT type=hidden name=ACTION value=SAVEITEM>
<H2>Your info</h2>[%ITEM;#LASTCREATED|5#;182 183 184;;;<table cellpadding=0 cellspacing=0 class=form>;</table>;<tr><td>#FIELDNAME:</td><td>#FIELDINPUT#</td></tr>%]<input type="image" onclick="checkform(frmEditItem)" src='media/buttons/joinsite.gif ' alt='Click to join us'></form>



The validation ALSO works fine,, but it submits when i click the alert.
Basicly i want to run validation untill return true.,..and ONLY then do the submit part of my script.

Again, many thanks in advance.

Matola

Oh also my validation works from the "ID" of my form element, instead of the "name", this seems ok ? Hope so as the name is generated dynamicly again.

P.S what a brilliant site this is.

voxecho
03-29-2007, 04:48 PM
you need a return false; after the funciton call. since the default action of an input type="image" is submit, it will submit the form if not told not to.

onclick="return(checkform(frmEditItem));"

matola
04-02-2007, 11:24 AM
Many thanks for your help, now my form does not submit onclick :)

But it never get to run the return true part of my script:

return true;
{
document.frmEditItem.V_ITEM_ID.value='531';
document.frmEditItem.submit();
}
}

Another tip would really help me, thanks again.
Matola

Philip M
04-02-2007, 03:20 PM
document.frmEditItem.V_ITEM_ID.value='531';
return true;

return true must be the final line of the function.

This causes
onclick="return(checkform(frmEditItem));"
to submit the form