Again Reposted- Still not had a response from this one

Thanks getting very close now, thanks for everyone that has helped me get to this stage

Excellent, thanks again for helping me out. The combo box created now creates a new one for every selection.

Now I still have the following two major issues. 1) Firstly I need to be able to send the selection from the second combo box by php. 2) secondly I need the combo box to appear within the table. (I thought this should be easy, but for the life of me cannot figure out how to get the dynamic combo into my table inside the form)

I have managed to send the selection from the first combo box with the form and also I can send a selection from the second combo, however onsubmit regardless of what is selected in the second combo box it simply sends the last option not the one selected. I have spent many hours trying to figure out why this is the case to no avail.

I have included my code for anyone who may be able to help. Lastly when I have figured out these 2 (with a little help) I should be able to sort out the validation by myself. Please ignore any code that is not relevant

<html>
<head>

<script type="text/javascript">

var this1;

window.onload = function() {
if (!document.all) document.captureEvents(Event.CHANGE);
document.getElementById('myddl').onchange = readDDL1; }

function readDDL1() {
var ddlobj = document.getElementById('myddl');
var currentSelection = ddlobj.options[ddlobj.options.selectedIndex].value;
if (currentSelection == '') currentSelection = ddlobj.options[ddlobj.options.selectedIndex].text;
doDDL2(currentSelection);
}

function doDDL2(ddl1Selection) {

var existingDDL2;
if ((existingDDL2 = document.getElementById('myddl2')) != null) existingDDL2.parentNode.removeChild(existingDDL2);

var ddl2Options;
switch (ddl1Selection) {
case "Western Australia":
ddl2Options = ["Please Select A Location", "Karratha", "Perth"]; break;
case "Queensland":
ddl2Options = ["Please Select A Location", "Brisbane", "Gold Coast"]; break;
}

if (typeof ddl2Options == "object") {
ddl2 = document.createElement('select');

ddl2.id = "myddl2";
var forVar;
for (forVar in ddl2Options) {
var newOption = document.createElement('option');
newOption.appendChild(document.createTextNode(ddl2Options[forVar]));
ddl2.appendChild(newOption);


}
document.body.appendChild(ddl2);

}

document.testform.this1.value = ((ddl2Options[forVar]));

}



function checkFrequency() {
return ShowResults();

}


function validate(){
var digits="0123456789"
var temp

if (document.testform.location.selectedIndex == 0) {
alert("Please Select a State");
return false
}

if (document.testform.location2.selectedIndex == 0) {
alert("Please Select a Location");
return false
}

return true
}




</script>

<style type="text/css">
.td_freq { background-color:yellow;
height:40px;
text-align:center;
}
.td_sev { background-colorink;
height:40px;
text-align:center;
}
.td_wi { background-color:lightgreen;
height:40px;
text-align:center;
}
</style>

</head>
<body>

<FORM name="testform" action='./emlapd.php' method='post' onsubmit="return checkFrequency()">

<input type='hidden' name='this1'>

<table align="center" border="1" width="40%">

<tr><td><b>Current Worksite State:</b><font color="red">*</font></td>
<td>
<select name="location" width='53' id="myddl">
<option value="0">--- Please Select Your State --- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
<option value="Western Australia">Western Australia</option>
<option value="Queensland">Queensland</option>

</select>

</td></tr>
<tr><td><b>Location:</b><font color="red">*</font></td>
<td>

</td></tr>

</table>


<tr>
<th colspan="2">
<input type="submit" name='submit' value="Submit" onclick= "return validate()">
</th>
<td colspan="10">&nbsp;</td>
<th>
<input type='reset' name='reset' value='Clear Form'>
</th>
</tr>
</table>

</FORM>
</body>
</html>


Thankyou very much to everyone that may help
Reply With Quote Multi-Quote This Message Quick reply to this message
J1000
View Public Profile
Send a private message to J1000
Find all posts by J1000
Add J1000 to Your Contacts
#2 Report Post
Old 08-05-2009, 04:27 PM
mitya mitya is offline
Registered User

Join Date: Oct 2003
Location: Nottingham
Posts: 488
Sorry, I forgot to come back to you on this.

1) Dynamic select box going in the form - that's because my script appends it to the document, i.e. the end of it, not to the specifically to the form. To do this, give your form an ID, say 'formie', and change the line in my code from

Code:

document.body.appendChild(ddl2);

to

Code:

document.getElementById('formie').appendChild(ddl2);

This will put it in your form and, thus, it will be sent along with the other values to the form handler.
Reply With Quote Multi-Quote This Message Quick reply to this message
mitya
View Public Profile
Visit mitya's homepage!
Find all posts by mitya
Add mitya to Your Contacts
#3 Report Post
Old 08-06-2009, 08:41 AM
J1000 J1000 is online now
Registered User

Join Date: Oct 2008
Location: Australia
Posts: 15
Question
First of all thanks again Mitya you are and have been a great help

Firstly
Thanks, that does indeed place the DDL inside the form, however it places it at the end of the form. I will have a play around and see if I can get it at a specific position in the form.

Unfortunately your method for appending by form id has the same problem as my previous method. Irregardless of the selection it simply posts the last option from the DDL not the one selected. Therefore I am still pretty much in the same position as I still want the second combo box to appear immediately below the first combo box and whatever option is selected from the second combo box I want to be posted with the rest of the form data.

If you have any other ideas that would be great
Reply With Quote Multi-Quote This Message Quick reply to this message
J1000
View Public Profile
Send a private message to J1000
Find all posts by J1000
Add J1000 to Your Contacts
#4 Report Post
Old 08-06-2009, 08:55 AM
J1000 J1000 is online now
Registered User

Join Date: Oct 2008
Location: Australia
Posts: 15
Question
Ok sorry early mornings cause mistakes. Obviously the reason I am still getting the same incorrect post is because the variable posted is still this1 from my code which reads the last value from the DDL. I have tried with all other variables to send as well ie ddl2 however still can't seem to send the selection.

So if your code works to create the variable for selection within the form what variable is it? So in its current state how can I send the selection and place the second DDL within the form??
Reply With Quote