Jump to content
  • 0

События на выбор option в select


alex_anderr
 Share

Question

В хтмл:


<select id="test" onchange="selectChanged(this.value);">
<option value="#">Выберите раздел</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>

JavaScript


$(document).ready(function(){
function selectChanged(value) {
switch(value) {
case 1:
func1();
break;
case 2:
func2();
break
}
}
});

Хочу вставить функцию "замены дива" на jquery аяксе в func1()


$("#test").val('1', function() {
$("#rubric3").empty();
$("#rubric4").empty().load("rubric_4step.php #last2");
});

Все осложняется тем, что selectChanged не работает.

Да и как вставить функцию в case пока дается тоже с трудом :)

В JS силен меньше всего, спасибо за помощь.

Случай средней тяжести, т.к. приходится учиться быстро.

С радостью приму любые ссылки, если не ответы.

Link to comment
Share on other sites

13 answers to this question

Recommended Posts

  • 0

<!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="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready()
{
$('#test').change(function()
{
switch($(this).val())
{
case '1':
$('#rubric3').html('Эмулируем аякс');
break;
case '2':
$('#rubric4').html('Эмулируем аякс');
break;
default:
break;
}
});
}
</script>

</head>

<body>
<select id="test">
<option value="#">Выберите раздел</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
<div id="rubric3">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</div>
<div id="rubric4">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</div>
</body>
</html>

В Фиддл работает. Локально нет. Странно или туплю?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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. See more about our Guidelines and Privacy Policy