Jump to content

replace a function help


tryingtolearn

Recommended Posts

Hi all,

I have a form that is populating select boxes dependamt on what is selected in the box before it.

It is all working fine.

I have to replace a function in it though to remove a replace function and Im not sure exactly how to do it.

 

This is the code working fine

<script type="text/javascript"> 	
var categories = [];
categories["startList"] = ["1","2","3"]
categories["1"] = ["a", "aa", "aaa"];
categories["2"] = ["b", "bb"];
categories["3"] = ["c", "cc", "ccc", "cccc", "ccccc"];

categories["a"] = ["1a", "2a"];
categories["aa"] = ["3a", "4a"];
categories["aaa"] = ["5a", "6a"];
categories["b" Intel"] = [];
categories["bb"] = ["8a"];
categories["c"] = ["9a", "10a"];
categories["cc"] = ["11a"];
categories["ccc"] =[];
categories["cccc"] = ["12a", "13a", "14a", "15a"];
categories["ccccc"] = ["16a", "17a", "18a", "19a"];
var nLists = 3; 
function fillSelect(currCat,currList){
	var step = Number(currList.name.replace(/\D/g,""));
	for (i=step; i<nLists+1; i++)
		{
		 document.forms[0]['List'+i].length = 1;
		 document.forms[0]['List'+i].selectedIndex = 0;
		}
	var nCat = categories[currCat];
	for (each in nCat)
		{
		 var nOption = document.createElement('option'); 
		 var nData = document.createTextNode(nCat[each]); 
		 nOption.setAttribute('value',nCat[each]); 
		 nOption.appendChild(nData); 
		 currList.appendChild(nOption); 
		} 
}	
function init(){
	fillSelect('startList',document.forms[0]['List1'])
}
onload=init;
function fabString(){
    document.getElementById('fabStringDrop').value = document.getElementById('List1').value+' '+document.getElementById('List2').value+' '+document.getElementById('List3').value
    return true;
}
</script>

<form name="Search" method="GET" action="#" target="_blank" onsubmit="return fabString()">
      <input type="hidden" name="_nkw" id="fabStringDrop" value="">  


	<select name='List1' onchange="fillSelect(this.value,this.form['List2'])">
		<option selected>Make a selection</option>
	</select>
	<br /><br />

	<select name='List2' onchange="fillSelect(this.value,this.form['List3'])">
		<option selected>Make a selection</option>
	</select>
	<br /><br />

	<select name='List3'>
		<option selected >Make a selection</option>

	</select><br /><br />
       <input type="submit" value="Search">
</form>

 

This is the part I need to replace

var step = Number(currList.name.replace(/\D/g,""));
	for (i=step; i<nLists+1; i++)
		{
		 document.forms[0]['List'+i].length = 1;
		 document.forms[0]['List'+i].selectedIndex = 0;
		}

 

I cannot use the replace part how I need to use this.

How can I code that directly in the script to reset each of the form fields if the option selected changes?

I hope that makes sense.

Link to comment
https://forums.phpfreaks.com/topic/188802-replace-a-function-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.