Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function help 1

Status
Not open for further replies.

thompom

Technical User
Dec 4, 2006
395
GB
Hi,

Trying to get the following function to

-run validation func
-if false dont do anything
-if true set x_action to 'A'
-submit the form

my function looks like
Code:
<script type="text/javascript">
function fzeventaddsend(){
return ew_ValidateForm(fzeventadd);
document.fzeventadd.x_action.value='A';
document.fzeventadd.submit();
}
</script>
at the moment the validation works fine - but after
the validation is correct the other parts are not run.

the onclick event is an image
Code:
<input type="image" src="images/nextbut.gif" name="btnAction" id="btnAction" onClick="fzeventaddsend();">


 
Hi

There is no life after an unconditional [tt]return[/tt] :
Code:
function fzeventaddsend()
{
  return ew_ValidateForm(fzeventadd); [gray]// execution ends here[/gray]
  [highlight silver]document.fzeventadd.x_action.value='A';[/highlight] [gray]// never executed[/gray]
  [highlight silver]document.fzeventadd.submit();[/highlight]
}
So modify it like this :
Code:
function fzeventaddsend()
{
  [red]if (![/red]ew_ValidateForm(fzeventadd)[red]) return false[/red];
  document.fzeventadd.x_action.value='A';
  document.fzeventadd.submit();
  [red]return true;[/red]
}

[gray]// or[/gray]

function fzeventaddsend()
{
  [red]var retval=[/red]ew_ValidateForm(fzeventadd);
  [red]if (retval) {[/red]
    document.fzeventadd.x_action.value='A';
    document.fzeventadd.submit();
  [red]}[/red]
  [red]return retval;[/red]
}
Note that such validation usually is bound to the [tt]form[/tt]'s [tt]onsubmit[/tt] event. But you know the circumstances better.

Feherke.
 
thanks again Feherke - heres a *

used to run this from the form's onsubmit but have moved the buttons outside the form tag - due to design issues - and need to fire the submit manually
 
hi - I want to pass the form name to the function
so I can reuse it - so:

Code:
<script type="text/javascript">
function addsend(formvar)
{
  if (!ew_ValidateForm(formvar)) return false;
  document.formvar.x_action.value='A';
  document.formvar.submit();
  return true;
}
</script>

<input type="image" src="images/nextbut.gif" name="btnAction" id="btnAction" onClick="addsend('fzeventadd');">

but i get an error "elements is NULL or not an object"
when passing the form name to the validate function.

Did an alert of formvar and is being passed OK

any ideas welcome
 
Hi

Code:
function addsend(formvar)
{
  if (!ew_ValidateForm(formvar)) return false;
  document.[red]forms[[/red]formvar[red]][/red].x_action.value='A';
  document.[red]forms[[/red]formvar[red]][/red].submit();
  return true;
}


Feherke.
 
Hi,

still getting an error "elements is NULL or not an object"
but - is on the red line after the validate function is called

Code:
function ew_ValidateForm(fobj) {
if (fobj.a_confirm && fobj.a_confirm.value == "F")
		return true;
var i, elm, aelm, infix;
var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
for (i=0; i<rowcnt; i++) {
infix = (fobj.key_count) ? String(i+1) : "";
[red]elm = fobj.elements["x" + infix + "_siteid"];[/red]
 
Hi

There you are expecting a reference, while there was passed the [tt]form[/tt]'s name. Change it like this :
Code:
<script type="text/javascript">
function addsend(formvar)
{
  if (!ew_ValidateForm(formvar)) return false;
  formvar.x_action.value='A';
  formvar.submit();
  return true;
}
</script>

<input type="image" src="images/nextbut.gif" name="btnAction" id="btnAction" onClick="addsend([red]document.[/red]fzeventadd);">
After this, the [tt]ew_ValidateForm()[/tt] needs no changes.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top