PDA

View Full Version : Multiple form instance of Form dependency not working



schwim
05-15-2007, 04:12 AM
1) Script Title: Form Dependency Manager

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex16/formdependency.htm

3) Describe problem:

Hi there,



<script type="text/javascript">
window.onload = function() {
setupDependencies('weboptions'); //name of form(s). Seperate each with a comma (ie: 'weboptions', 'myotherform' )
};
</script>


I'm trying to get this script to work with two forms. However, no matter what I do, I can only get it working with one or the other. Never both.

I've tried:



<script type="text/javascript">
window.onload = function() {
setupDependencies('form1','form2');
};
</script>




<script type="text/javascript">
window.onload = function() {
setupDependencies('form1', 'form2' );
};
</script>

&


<script type="text/javascript">
window.onload = function() {
setupDependencies('form1',
'form2');
};


But only the first form listed works. If I delete form1 and put form2 in it's place, form2 begins using the script properly. I just can't get both to use the script.

Could someone tell me what I'm doing wrong?

thanks,
json
</script>

Twey
05-15-2007, 04:40 AM
Hmm, there's no reason it shouldn't work with both unless there's something odd going on with your forms. Can we see the page?

schwim
05-15-2007, 04:55 AM
Hi there Twey, and thanks for the reply,

here's the html being generated:



<html>
<head>
<title>Briarfield Cafe <~> Employment Application</title>
<script src="FormManager.js">
/****************************************************
* Form Dependency Manager- By Twey- http://www.twey.co.uk
* Visit Dynamic Drive for this script and more: http://www.dynamicdrive.com
****************************************************/
</script>

<script type="text/javascript">
window.onload = function() {
setupDependencies('employment_app', 'verify');
};
</script>

<script type="text/javascript">

/***********************************************
* Textarea Maxlength script- � Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

</script>

<STYLE TYPE="text/css">
<!--
div.error {
border: 2px dashed #333;
padding: 10px;
background-color: #ffe;
}
-->
</STYLE>

</head>
<body>

<center><h1>Your application is being validated</h1></center><br><br><form name='verify' method='post' action='application.php?action=verify'>
<div class='error'><b><font color='red'>Error:</font></b> No response:<br>
Are you eligible to work in the United States?<br>(<INPUT TYPE='radio' NAME='able_work' VALUE='yes'>Yes) or (<INPUT TYPE='radio' NAME='able_work' VALUE='no'>No)</div>
<br>

<input type='hidden' name='verify' value='1'>
<div class='error'><b><font color='red'>Error:</font></b> No response:<br>
If you are under age 18, do you have an employment/age certificates?<br>
(<INPUT TYPE='radio' NAME='work_cert' VALUE='yes'>Yes) or (<INPUT TYPE='radio' NAME='work_cert' VALUE='no'>No)</div>
<br>

<input type='hidden' name='verify' value='1'><div class='error'><b><font color='red'>Error:</font></b> No response:<br>
Have you been convicted of or pleaded no contest to a felony within the last five years?
<br>
<label>Yes<input type='radio' name='conviction' value='con_yes'></label>
<label>No<input type='radio' name='conviction' value='con_no'></label>
<label style='margin-bottom: 1em; padding-bottom: 1em; border-bottom: 3px silver groove;'><input type='hidden' class='DEPENDS ON os BEING linux OR os BEING windows'></label>
<label><br>

<br>
Please Explain:<br>
<textarea name='convict_ex' cols=60 rows=10 maxlength="500" onkeyup="return ismaxlength(this)" class='DEPENDS ON conviction BEING con_yes'></textarea><br>
</label></form></body></html>


This page is being generated by PHP. The head content is being shared by both pages(and forms), so if one works, logic would dictate that the head content wouldn't be the problem for the second form which leads me to believe that I've messed up in the body.

Problem is though that I simply copied & pasted the form element from the working form to the non-working one. I didn't intentionally change anything.

Any light you could shed would be greatly appreciated.

thanks,
json

schwim
05-16-2007, 01:27 AM
Hi there twey,

I fixed it with a PHP if/else. It wasn't working with more than one form listed.

thanks,
json

Twey
05-16-2007, 05:05 PM
<label style='margin-bottom: 1em; padding-bottom: 1em; border-bottom: 3px silver groove;'><input type='hidden' class='DEPENDS ON os BEING linux OR os BEING windows'></label>Uh, that's from the demo and bears no relevance to your form.

schwim
05-17-2007, 12:51 AM
Thanks very much for that, but I would also have to say that it bears no relevence to my problem, either.

Uh,
json