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!

Changing a SELECT value to NULL

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Hi,

I've written a little scripts (AJAX +JS), which lets users build up a category "tree". For example:

They select "Europe". The next one will load "UK", "France", "Germany", etc ... then the next one would load "counties", the next one "cities", and finally road names.

Now, this all works ... but when someone selects a field, and then goes back a couple of SELECT boxes - it still holds the values for the field.

For example - the data pass into the script could look something like:

article_is_in_1 => 2345
article_is_in_2 => 345
article_is_in_3 => 546456
article_is_in_4 => 2345

..and if they go back to the select box 2, it would look something like:

article_is_in_1 => 2345
article_is_in_2 => 345
article_is_in_3 =>
article_is_in_4 => 2345

What I need to do, is set that value (article_is_in_4), to NULL (or -1)

Can anyone suggest how to do this? I'm using JQuery btw - if that helps =)

TIA

Andy
 
perhaps this will help.



I don't fully understand your question, but I think you want to dynamicaly add/change select lists..


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Thanks - managed to get it working with:


Code:
			 jQuery('#article_is_in_4').value = '0';
			 jQuery('#article_is_in_5').value = '0';
			 jQuery('#article_is_in_6').value = '0';
			 jQuery('#article_is_in_7').value = '0';
			 jQuery('#article_is_in_8').value = '0';
			 jQuery('#article_is_in_9').value = '0';
			 jQuery('#article_is_in_10').value = '0';
			 jQuery('#article_is_in_11').value = '0';
			 jQuery('#article_is_in_12').value = '0';
			 jQuery('#article_is_in_13').value = '0';
			 jQuery('#article_is_in_14').value = '0';
			 jQuery('#article_is_in_15').value = '0';
 
Mmm, maybe that didn't work :(

Tried:

Code:
document.getElementById("article_is_in_2").value = 'BLA';
		document.getElementById("article_is_in_3").value = 'BLA';
		document.getElementById("article_is_in_4").value = 'BLA';
		document.getElementById("article_is_in_5").value = 'BLA';
		document.getElementById("article_is_in_6").value = 'BLA';
		document.getElementById("article_is_in_7").value = 'BLA';
		document.getElementById("article_is_in_8").value = 'BLA';
		document.getElementById("article_is_in_9").value = 'BLA';
		document.getElementById("article_is_in_10").value = 'BLA';
		document.getElementById("article_is_in_11").value = 'BLA';
		document.getElementById("article_is_in_12").value = 'BLA';
		document.getElementById("article_is_in_13").value = 'BLA';
		document.getElementById("article_is_in_14").value = 'BLA';

..and also:

Code:
        jQuery('#article_is_in_2').value = -1;
        jQuery('#article_is_in_3').value = -1;
        jQuery('#article_is_in_4').value = -1;
        jQuery('#article_is_in_5').value = -1;
        jQuery('#article_is_in_6').value = -1;

..but the values still get submitted :(

any ideas?

Cheers
 
Damn it - still cant get it working :(

I'm just trying a VERY basic test, which will "delete" the content of a SELECT div, i.e:

Code:
<html>

<head>
<script type="text/javascript" src="/static/jquery.js"></script>


<script>

function dotest() {

    jQuery.noConflict();
  
	jQuery("#testing").remove();
 
}

dotest();

</script>




<form name="search_form" action="test.cgi" method="POST">

  <div id="testing" name="testing">
	<select name="article_is_in_1" id="article_is_in_1">
	<option value="-1">- Your Province -</option>
	<option value="9243">Uk</option>
	</select>
  </div>

</form>



</html>

...but nothing happens at all.

I thought the remove() function removes ALL the content from inside a div?

TIA

Andy
 
Even doing this basic test does't seem to work (based on an example I found on several websites);


Code:
<html>

<head>
<script type="text/javascript" src="/static/jquery.js"></script>


<script>

  alert("HERE");
   $("article_is_in_1").removeOption(/./);
   alert("HERE 2");

</script>

</head>

<body>

<form name="search_form" action="test.cgi" method="POST">

	<select name="article_is_in_1" id="article_is_in_1">
		<option value="-1">- Your Province -</option>
		<option value="9243">Uk</option>
	</select>



</form>

</body>


</html>

..I get this error:

Error: $("article_is_in_1").removeOption is not a function
Source File: Line: 10


How ON EARTH do you remove ALL the values from a SELECT field? Its driving me nuts!!

TIA

Andy
 
Anyone?

I'm trying a simpler solution now - but that doesn't seem to work either :(



Code:
function clear_further_up(field_num) {

		 var field_name = "article_is_in_" + field_num;

         jQuery("select#" + field_name).change(function(){
	         options += '<option value="0">na</option>';
	         jQuery("#" +field_name).html(options);
	         jQuery('#' +field_name+ ' option:first').attr('selected', 'selected');
		 });

}

..and calling with:

function clear_further_up(1)

Any ideas why its not working?

TIA

Andy
 
Phew, finally got it working:

Code:
function clear_further_up(field_num) {

         for (var i = field_num; i < 14; i++) {		

			 var field_name = "article_is_in_" + i;

			document.getElementById(field_name).length = 0;

		}

}

Will this work accross all browsers?

TIA

Andy
 
look like normal JS to me.

Couldn't help with anything else as i don't do JS frameworks be it JQuery or any other, I like to code it all by hand myself :)

I was taught through this forum that Cargo Cult programming was bad.

Therefore that rules out the use of JS frameworks ;-)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top