...

View Full Version : Resolved Adding To Code



CoolAsCarlito
01-15-2011, 11:35 PM
I have this code:



$('#menuitemform select').change( function() {
$( '#menuitemform select' ).not( this ).val( 0 );
});


to prevent the user from making a selection from more than 1 select dropdown however I want to add something to this but not sure how.

Along with this I want to make the user not be able to also have input inside of a text box if one of the dropdowns has a selection. If one of them does then it erases the users input but its on a specific text box with an id of itemurl.

harbingerOTV
01-17-2011, 08:27 PM
If I understand correctly:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#menuitemform select').change( function() {
$('#menuitemform select' ).not(this).val(0);
if($("#s1").val().length > 0){
$("#itemurl").attr("value","");

}
});

});
</script>
</head>

<body>
<form id="menuitemform" method="POST" action="">
<select name="s1" id="s1">
<option value="">Select</option>
<option value="apples">Apples</option>
<option value="oranges">Oranges</option>
</select>
<select name="s2" id="s2">
<option value="">Select</option>
<option value="lions">Lions</option>
<option value="tigers">Tigers</option>
</select>
<input id="itemurl" name="itemurl" ttype="text" />
</form>
</body>
</html>

CoolAsCarlito
01-17-2011, 08:32 PM
So I was able to get it to work the way I asked however I wanted to also extend it so that if there was a value in the input field then the 3 dropdowns would reset back to the 0 values but its saying there is a js error which could only involve the code below.



$('#menuitemform select').change( function() {
$( '#menuitemform select' ).not( this ).val( 0 );
if ($("#menuitemform select").val().length > 0){
$("#itemurl").attr("value","");
}
});
if $("#itemurl").val().length > 0){
$( '#menuitemform select' ).not( this ).val( 0 );
}

harbingerOTV
01-17-2011, 09:44 PM
So if any select has a chosen value, let it e the only select that has value and clear the input.

But, If the input has value, reset the selects?

right?

try:

$('#menuitemform select').change(function(){
$("#itemurl").removeAttr('disabled');
$('#menuitemform select').not(this).val(0);
$('#menuitemform select').each(function(){
if($(this).val().length > 0){
$("#itemurl").attr("value","");
//$("#itemurl").attr('disabled','disabled');
}
});
});
$("#itemurl").focus(function(){
$('#menuitemform select').val(0);
});

CoolAsCarlito
01-17-2011, 09:56 PM
GENIUS. However is it safe for me to delete that commented line. And thank you VERY MUCH.

harbingerOTV
01-17-2011, 10:03 PM
More than safe. i was just using it for testing.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum