Jump to content

A little Javascript problem


selenin

Recommended Posts

Hello, I just try to modify a script and I have this problem

 

My Javascript code:

 

<script type="text/javascript">

jQuery(document).ready(

  function() {

catlist();

  });

 

  $(document).ready(function(){

  $("#pm_sources").change(function () {

  var str = $("select option:selected").attr('value');

  $("#pm_sources_ex").text(str);

  })

  .change();

  });

 

</script>

 

My Template Code:

 

			<select name="category" size="1" >
		<option value="-1">{$lang.select}</option>
			{foreach from=$categories_list key=k item=v}
			<option value="{$k}" {if $smarty.post.category == $k}selected{/if}>{$v}</option>
			{/foreach}
		</select>



		<select name="" id="pm_sources" size="1" >
			<option selected="selected">{$lang.select}</option>
			{foreach from=$sources key=k item=v}
			  <option value="{$v.url_example}">{$v.source_name|capitalize}</option>
			{/foreach}
		</select>
		<input type="text" name="yt_id" value="{$smarty.post.yt_id}" size="60" class="inputtext" />
		 <br /><small>Example: <span id="pm_sources_ex"></span></small>

 

My problem is when I put pm_sources before the category it works fine, but like I want to have it like this order it takes for pm_sources_ex the -1 from categories  :shrug:

Link to comment
https://forums.phpfreaks.com/topic/203678-a-little-javascript-problem/
Share on other sites

No problem. I was also able to get it to work using what I told you try in my first reply.

 

<html>
<head>
<title>Select Test</title>
<script src="jquery-1.4.2.min.js"></script>
<script>
$(document).ready(function() {
$('#firstSelect').change(function() {
	alert($(this).val());
});

$('#secondSelect').change(function() {
	alert($(this).val());
});
});
</script>
</head>
<body>
<select id="firstSelect">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<select id="secondSelect">
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</body>
</html>

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.